Open
Description
Code
dbg!("since when is \“THIS\” not allowed in a string literal");
Current output
error: unknown character escape: `\u{201c}`
--> src/main.rs:2:26
|
2 | dbg!("since when is \“THIS\” not allowed in a string literal");
| ^ unknown character escape
|
= help: for more information, visit <https://doc.rust-lang.org/reference/tokens.html#literals>
help: if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal
|
2 | dbg!(r"since when is \“THIS\” not allowed in a string literal");
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: unknown character escape: `\u{201d}`
--> src/main.rs:2:32
|
2 | dbg!("since when is \“THIS\” not allowed in a string literal");
| ^ unknown character escape
|
= help: for more information, visit <https://doc.rust-lang.org/reference/tokens.html#literals>
help: if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal
|
2 | dbg!(r"since when is \“THIS\” not allowed in a string literal");
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Desired output
error: unknown character escape: Unicode "Left Double Quotation Mark" (`\u{201c}`)
--> src/main.rs:2:26
|
2 | dbg!("since when is \“THIS\” not allowed in a string literal");
| ^ unknown character escape
|
= help: Unicode quotation marks (“ ”) do not need to be escaped as they do not terminate a string literal.
help: remove the backslash
|
2 | dbg!(r"since when is “THIS” not allowed in a string literal");
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: unknown character escape: Unicode "Right Double Quotation Mark" (`\u{201d}`)
--> src/main.rs:2:32
|
2 | dbg!("since when is \“THIS\” not allowed in a string literal");
| ^ unknown character escape
|
= help: Unicode quotation marks (“ ”) do not need to be escaped as they do not terminate a
string literal.
help: remove the backslash
|
2 | dbg!(r"since when is “THIS” not allowed in a string literal");
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rationale and extra context
I copied some text from a webpage to add to an error message, and noticing the quotation marks (which are indistinguishable from ASCII double-quotes in the monospaced font I'm using), I proactively added backslash-escapes and then spent the next ten minutes scratching my head and wondering why the compiler was complaining.
I thought this might be some obtuse Clippy lint, suggesting raw string literals over escapes, before I realized it was an actual parse error.
Seeing as there's a help message for the Greek Question Mark (;
), this would also be nice to have.
Other cases
No response
Rust Version
$ rustc --version --verbose
rustc 1.80.0 (051478957 2024-07-21)
binary: rustc
commit-hash: 051478957371ee0084a7c0913941d2a8c4757bb9
commit-date: 2024-07-21
host: x86_64-unknown-linux-gnu
release: 1.80.0
LLVM version: 18.1.7
Anything else?
No response