rust-lang / rust-lang/rust

Hint on unknown escape of Unicode quotation marks in string literal

Open
#128,858 5 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

A-diagnostics C-enhancement T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.