-
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
Open
LFS6502
wants to merge
6
commits into
rust-lang:master
Choose a base branch
from
LFS6502:unicode-quote-hint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+154
−0
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f3daf63
Hint on unknown escape of Unicode quotation marks in string literal
lolbinarycat c9e0f09
fmt
lolbinarycat 206dc78
Implement suggested fix and update test
LFS6502 1f9345d
Add comment to test
LFS6502 4d80eef
Rework test
LFS6502 f278b59
Remove error line numbers and fix capitalization.
LFS6502 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; \ | ||||||
LFS6502 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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
|
||||||
)); | ||||||
} 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, | ||||||
} | ||||||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 4:12: 4:13: unknown character escape: `\u{2033}` | ||
LFS6502 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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}` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.