Skip to content

Commit 2cf9a61

Browse files
committed
Tweak wording
1 parent d565d2f commit 2cf9a61

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

compiler/rustc_parse/src/lib.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_ast::tokenstream::TokenStream;
2323
use rustc_ast::{AttrItem, Attribute, MetaItemInner, token};
2424
use rustc_ast_pretty::pprust;
2525
use rustc_data_structures::sync::Lrc;
26-
use rustc_errors::{Diag, EmissionGuarantee, FatalError, PResult};
26+
use rustc_errors::{Diag, EmissionGuarantee, FatalError, PResult, pluralize};
2727
use rustc_session::parse::ParseSess;
2828
use rustc_span::source_map::SourceMap;
2929
use rustc_span::{FileName, SourceFile, Span};
@@ -112,7 +112,16 @@ pub fn utf8_error<E: EmissionGuarantee>(
112112
let start = utf8err.valid_up_to();
113113
let note = format!("invalid utf-8 at byte `{start}`");
114114
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+
)
116125
} else {
117126
note.clone()
118127
};

tests/ui/macros/not-utf8.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: couldn't read `$DIR/not-utf8.bin`: stream did not contain valid UTF-8
44
LL | include!("not-utf8.bin");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: `[193]` is not valid utf-8
7+
note: byte `193` is not valid utf-8
88
--> $DIR/not-utf8.bin:1:1
99
|
1010
LL | �|�␂!5�cc␕␂�Ӻi��WWj�ȥ�'�}�␒�J�ȉ��W�␞O�@����␜w�V���LO����␔[ ␃_�'���SQ�~ذ��ų&��- ��lN~��!@␌ _#���kQ��h�␝�:�...

0 commit comments

Comments
 (0)