Hint on unknown escape of Unicode quotation marks in string literal#137067
Hint on unknown escape of Unicode quotation marks in string literal#137067LFS6502 wants to merge 6 commits into
Conversation
Fixes rust-lang#128858 I opted not to produce a suggestion, since it's not obvious what the user meant to do.
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
This comment has been minimized.
This comment has been minimized.
|
closes #128906 |
|
@jieyouxu @compiler-errors @Dylan-DPC If you've got some spare time, I'd love some input from you too. I will squash at the end. |
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: \u{201c} is not an ascii quote, but may look like one in some fonts; consider writing it in its escaped form for clarity.
help: if you meant to use a unicode quote; consider using its escaped form for clarity
|
2 - dbg!("since when is \“THIS\” not allowed in a string literal");
2 + dbg!("since when is \u{201c}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: \u{201d} is not an ascii quote, but may look like one in some fonts; consider writing it in its escaped form for clarity.
help: if you meant to use a unicode quote; consider using its escaped form for clarity
|
2 - dbg!("since when is \“THIS\” not allowed in a string literal");
2 + dbg!("since when is \“THIS\u{201d} not allowed in a string literal");
|
error: could not compile `diag` (bin "diag") due to 2 previous errorsIn image form: |
|
Assigning review to Michael because of this comment in the previous version of a patch. |
|
kinda busy so re-rolling r? compiler |
Noratrieb
left a comment
There was a problem hiding this comment.
thanks, this looks good overall, some small suggestions, then you can squash it and we can merge it.
I'm not entirely convinced the suggestion is worth it, since it seems really unlikely someone would write this on purpose intending anything other than what the issue author intended. But it's fine to have if you think it's good
| err_span, | ||
| "if you meant to use a unicode quote; \ | ||
| consider using its escaped form for clarity", | ||
| // lit.replace(c, &ec[1..]), |
There was a problem hiding this comment.
looks like this was left over from development
There was a problem hiding this comment.
This still needs to be addressed.
Co-authored-by: nora <48135649+Noratrieb@users.noreply.github.com>
|
The job Click to see the possible cause of the failure (guessed by this bot) |
| err_span, | ||
| "if you meant to use a unicode quote; \ | ||
| consider using its escaped form for clarity", | ||
| // lit.replace(c, &ec[1..]), |
There was a problem hiding this comment.
This still needs to be addressed.
|
|
||
| diag.help(format!( | ||
| "{ec} is not an ASCII quote, but may look like one in some fonts; \ | ||
| consider writing it in its escaped form for clarity." |
There was a problem hiding this comment.
| consider writing it in its escaped form for clarity." | |
| consider writing it in its escaped form for clarity" |
| diag.span_suggestion( | ||
| err_span, | ||
| "if you meant to use a unicode quote; \ | ||
| consider using its escaped form for clarity", | ||
| // lit.replace(c, &ec[1..]), | ||
| &ec, | ||
| Applicability::MaybeIncorrect, | ||
| ); | ||
|
|
||
| diag.help(format!( | ||
| "{ec} is not an ASCII quote, but may look like one in some fonts; \ | ||
| consider writing it in its escaped form for clarity." | ||
| )); |
There was a problem hiding this comment.
Instead of emitting both a help and a suggestion, use the message from the help in a span_suggestion_verbose. The text is effectively saying the same thing twice, the help message can have the explanation, that's preferable.
| // list of homoglyphs generated using the following wikidata query: | ||
| // SELECT ?u WHERE { | ||
| // wd:Q87495536 wdt:P2444+ ?c. | ||
| // ?c wdt:P4213 ?u. | ||
| // } |
There was a problem hiding this comment.
For future reference, I recall that the unicode tables have a "similarity" field that I've looked at in the past.
|
Thanks, working on this now. |
Fixes rust-lang#128858 Original work by @LFS6502 in PR rust-lang#137067, squashed. Continuation of PR rust-lang#128906. Signed-off-by: Giles Cope <gilescope@gmail.com>
Apply remaining review requests from estebank and Noratrieb on PR rust-lang#137067: - Remove leftover `// lit.replace(...)` development comment - Merge duplicated help+suggestion text by keeping the explanation in `help` and moving the actionable part into `span_suggestion_verbose` - Drop redundant line/column numbers from `//~^ERROR` annotations - Bless stderr (now matches the previously-applied `ASCII` capitalization fix and the zero-width-diacritic caret positions reported by CI) Signed-off-by: Giles Cope <gilescope@gmail.com>


Fixes #128858
Continuation of #128906