Skip to content

Commit 5418e15

Browse files
committed
Fix issue #64732
Based on issue #64732, when creating a byte literal with single quotes, the suggestion message would indicate that you meant to write a `str` literal, but we actually meant to write a byte string literal. So I changed the unescape_error_reporting.rs to decide whether to print out "if you meant to write a `str` literal, use double quotes", or "if you meant to write a byte string literal, use double quotes".
1 parent 6c2c29c commit 5418e15

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/libsyntax/parse/unescape_error_reporting.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,20 @@ pub(crate) fn emit_unescape_error(
4747
.emit();
4848
}
4949
EscapeError::MoreThanOneChar => {
50+
let msg = if mode.is_bytes() {
51+
"if you meant to write a byte string literal, use double quotes"
52+
} else {
53+
"if you meant to write a `str` literal, use double quotes"
54+
};
55+
5056
handler
5157
.struct_span_err(
5258
span_with_quotes,
5359
"character literal may only contain one codepoint",
5460
)
5561
.span_suggestion(
5662
span_with_quotes,
57-
"if you meant to write a `str` literal, use double quotes",
63+
msg,
5864
format!("\"{}\"", lit),
5965
Applicability::MachineApplicable,
6066
).emit()

0 commit comments

Comments
 (0)