@@ -23,7 +23,7 @@ use rustc_ast::tokenstream::TokenStream;
23
23
use rustc_ast:: { AttrItem , Attribute , MetaItemInner , token} ;
24
24
use rustc_ast_pretty:: pprust;
25
25
use rustc_data_structures:: sync:: Lrc ;
26
- use rustc_errors:: { Diag , EmissionGuarantee , FatalError , PResult } ;
26
+ use rustc_errors:: { Diag , EmissionGuarantee , FatalError , PResult , pluralize } ;
27
27
use rustc_session:: parse:: ParseSess ;
28
28
use rustc_span:: source_map:: SourceMap ;
29
29
use rustc_span:: { FileName , SourceFile , Span } ;
@@ -112,7 +112,16 @@ pub fn utf8_error<E: EmissionGuarantee>(
112
112
let start = utf8err. valid_up_to ( ) ;
113
113
let note = format ! ( "invalid utf-8 at byte `{start}`" ) ;
114
114
let msg = if let Some ( len) = utf8err. error_len ( ) {
115
- format ! ( "`{:?}` is not valid utf-8" , & contents[ start..start + len] )
115
+ format ! (
116
+ "byte{s} `{bytes}` {are} not valid utf-8" ,
117
+ bytes = if len == 1 {
118
+ format!( "{:?}" , contents[ start] )
119
+ } else {
120
+ format!( "{:?}" , & contents[ start..start + len] )
121
+ } ,
122
+ s = pluralize!( len) ,
123
+ are = if len == 1 { "is" } else { "are" } ,
124
+ )
116
125
} else {
117
126
note. clone ( )
118
127
} ;
0 commit comments