Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/libsyntax/parse/unescape_error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,20 @@ pub(crate) fn emit_unescape_error(
.emit();
}
EscapeError::MoreThanOneChar => {
let msg = if mode.is_bytes() {
"if you meant to write a byte string literal, use double quotes"
} else {
"if you meant to write a `str` literal, use double quotes"
};

handler
.struct_span_err(
span_with_quotes,
"character literal may only contain one codepoint",
)
.span_suggestion(
span_with_quotes,
"if you meant to write a `str` literal, use double quotes",
msg,
format!("\"{}\"", lit),
Applicability::MachineApplicable,
).emit()
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/issues/issue-64732.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![allow(unused)]
fn main() {
let _foo = b'hello\0';
//~^ ERROR character literal may only contain one codepoint
//~| HELP if you meant to write a byte string literal, use double quotes
let _bar = 'hello';
//~^ ERROR character literal may only contain one codepoint
//~| HELP if you meant to write a `str` literal, use double quotes
}
22 changes: 22 additions & 0 deletions src/test/ui/issues/issue-64732.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error: character literal may only contain one codepoint
--> $DIR/issue-64732.rs:3:17
|
LL | let _foo = b'hello\0';
| ^^^^^^^^^
help: if you meant to write a byte string literal, use double quotes
|
LL | let _foo = b"hello\0";
| ^^^^^^^^^

error: character literal may only contain one codepoint
--> $DIR/issue-64732.rs:6:16
|
LL | let _bar = 'hello';
| ^^^^^^^
help: if you meant to write a `str` literal, use double quotes
|
LL | let _bar = "hello";
| ^^^^^^^

error: aborting due to 2 previous errors