-
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?
Changes from all commits
f3daf63
c9e0f09
206dc78
1f9345d
4d80eef
f278b59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -158,6 +158,20 @@ pub(crate) fn emit_unescape_error( | |||||
"this is an isolated carriage return; consider checking your editor and \ | ||||||
version control settings", | ||||||
); | ||||||
} else if looks_like_quote(c) { | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
)); | ||||||
Comment on lines
+162
to
+174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of emitting both a |
||||||
} else { | ||||||
if mode == Mode::Str || mode == Mode::Char { | ||||||
diag.span_suggestion( | ||||||
|
@@ -295,3 +309,17 @@ pub(crate) fn escaped_char(c: char) -> String { | |||||
_ => c.escape_default().to_string(), | ||||||
} | ||||||
} | ||||||
|
||||||
/// Returns true if `c` may look identical to `"` in some fonts. | ||||||
fn looks_like_quote(c: char) -> bool { | ||||||
// list of homoglyphs generated using the following wikidata query: | ||||||
// SELECT ?u WHERE { | ||||||
// wd:Q87495536 wdt:P2444+ ?c. | ||||||
// ?c wdt:P4213 ?u. | ||||||
// } | ||||||
Comment on lines
+315
to
+319
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
match c { | ||||||
'\u{2033}' | '\u{02BA}' | '\u{02DD}' | '\u{030B}' | '\u{030E}' | '\u{05F4}' | ||||||
| '\u{201C}' | '\u{201D}' => true, | ||||||
_ => false, | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Provide a useful error message when attempting to escape a non-ascii quotation mark. | ||
// <https://github.com/rust-lang/rust/issues/128858> | ||
fn main() { | ||
dbg!("\″"); //U+2033 | ||
//~^ERROR unknown character escape: `\u{2033}` | ||
dbg!("\ʺ"); //U+02BA | ||
//~^ERROR 6:12: 6:13: unknown character escape: `\u{2ba}` | ||
dbg!("\˝"); //U+02DD | ||
//~^ERROR 8:12: 8:13: unknown character escape: `\u{2dd}` | ||
dbg!("\̋"); //U+030B | ||
//~^ERROR 10:12: 10:13: unknown character escape: `\u{30b}` | ||
dbg!("\̎"); //U+030E | ||
//~^ERROR 12:12: 12:13: unknown character escape: `\u{30e}` | ||
dbg!("\״"); //U+05F4 | ||
//~^ERROR 14:12: 14:13: unknown character escape: `\u{5f4}` | ||
dbg!("\“"); //U+201C | ||
//~^ERROR 16:12: 16:13: unknown character escape: `\u{201c}` | ||
dbg!("\”"); //U+201D | ||
//~^ERROR 18:12: 18:13: unknown character escape: `\u{201d}` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
error: unknown character escape: `\u{2033}` | ||
--> $DIR/unicode-quote.rs:4:12 | ||
| | ||
LL | dbg!("\″"); //U+2033 | ||
| ^ unknown character escape | ||
| | ||
= help: \u{2033} 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 | ||
| | ||
LL - dbg!("\″"); //U+2033 | ||
LL + dbg!("\u{2033}"); //U+2033 | ||
| | ||
|
||
error: unknown character escape: `\u{2ba}` | ||
--> $DIR/unicode-quote.rs:6:12 | ||
| | ||
LL | dbg!("\ʺ"); //U+02BA | ||
| ^ unknown character escape | ||
| | ||
= help: \u{2ba} 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 | ||
| | ||
LL - dbg!("\ʺ"); //U+02BA | ||
LL + dbg!("\u{2ba}"); //U+02BA | ||
| | ||
|
||
error: unknown character escape: `\u{2dd}` | ||
--> $DIR/unicode-quote.rs:8:12 | ||
| | ||
LL | dbg!("\˝"); //U+02DD | ||
| ^ unknown character escape | ||
| | ||
= help: \u{2dd} 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 | ||
| | ||
LL - dbg!("\˝"); //U+02DD | ||
LL + dbg!("\u{2dd}"); //U+02DD | ||
| | ||
|
||
error: unknown character escape: `\u{30b}` | ||
--> $DIR/unicode-quote.rs:10:12 | ||
| | ||
LL | dbg!("\̋"); //U+030B | ||
| ^ unknown character escape | ||
| | ||
= help: \u{30b} 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 | ||
| | ||
LL - dbg!("\̋"); //U+030B | ||
LL + dbg!("\u{30b}"); //U+030B | ||
| | ||
|
||
error: unknown character escape: `\u{30e}` | ||
--> $DIR/unicode-quote.rs:12:12 | ||
| | ||
LL | dbg!("\̎"); //U+030E | ||
| ^ unknown character escape | ||
| | ||
= help: \u{30e} 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 | ||
| | ||
LL - dbg!("\̎"); //U+030E | ||
LL + dbg!("\u{30e}"); //U+030E | ||
| | ||
|
||
error: unknown character escape: `\u{5f4}` | ||
--> $DIR/unicode-quote.rs:14:12 | ||
| | ||
LL | dbg!("\״"); //U+05F4 | ||
| ^ unknown character escape | ||
| | ||
= help: \u{5f4} 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 | ||
| | ||
LL - dbg!("\״"); //U+05F4 | ||
LL + dbg!("\u{5f4}"); //U+05F4 | ||
| | ||
|
||
error: unknown character escape: `\u{201c}` | ||
--> $DIR/unicode-quote.rs:16:12 | ||
| | ||
LL | dbg!("\“"); //U+201C | ||
| ^ 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 | ||
| | ||
LL - dbg!("\“"); //U+201C | ||
LL + dbg!("\u{201c}"); //U+201C | ||
| | ||
|
||
error: unknown character escape: `\u{201d}` | ||
--> $DIR/unicode-quote.rs:18:12 | ||
| | ||
LL | dbg!("\”"); //U+201D | ||
| ^ 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 | ||
| | ||
LL - dbg!("\”"); //U+201D | ||
LL + dbg!("\u{201d}"); //U+201D | ||
| | ||
|
||
error: aborting due to 8 previous errors | ||
|
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.