-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Hint on unknown escape of Unicode quotation marks in string literal #137067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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 errors In image form: |
Assigning review to Michael because of this comment in the previous version of a patch. |
kinda busy so re-rolling r? compiler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this was left over from development
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future reference, I recall that the unicode tables have a "similarity" field that I've looked at in the past.
Fixes #128858
Continuation of #128906