Skip to content

Commit

Permalink
Tweak wording
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jan 18, 2025
1 parent d565d2f commit 2cf9a61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions compiler/rustc_parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use rustc_ast::tokenstream::TokenStream;
use rustc_ast::{AttrItem, Attribute, MetaItemInner, token};
use rustc_ast_pretty::pprust;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{Diag, EmissionGuarantee, FatalError, PResult};
use rustc_errors::{Diag, EmissionGuarantee, FatalError, PResult, pluralize};
use rustc_session::parse::ParseSess;
use rustc_span::source_map::SourceMap;
use rustc_span::{FileName, SourceFile, Span};
Expand Down Expand Up @@ -112,7 +112,16 @@ pub fn utf8_error<E: EmissionGuarantee>(
let start = utf8err.valid_up_to();
let note = format!("invalid utf-8 at byte `{start}`");
let msg = if let Some(len) = utf8err.error_len() {
format!("`{:?}` is not valid utf-8", &contents[start..start + len])
format!(
"byte{s} `{bytes}` {are} not valid utf-8",
bytes = if len == 1 {
format!("{:?}", contents[start])
} else {
format!("{:?}", &contents[start..start + len])
},
s = pluralize!(len),
are = if len == 1 { "is" } else { "are" },
)
} else {
note.clone()
};
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/macros/not-utf8.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: couldn't read `$DIR/not-utf8.bin`: stream did not contain valid UTF-8
LL | include!("not-utf8.bin");
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: `[193]` is not valid utf-8
note: byte `193` is not valid utf-8
--> $DIR/not-utf8.bin:1:1
|
LL | �|�␂!5�cc␕␂�Ӻi��WWj�ȥ�'�}�␒�J�ȉ��W�␞O�@����␜w�V���LO����␔[ ␃_�'���SQ�~ذ��ų&��- ��lN~��!@␌ _#���kQ��h�␝�:�...
Expand Down

0 comments on commit 2cf9a61

Please sign in to comment.