File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed
compiler/rustc_parse/src/lexer Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -158,6 +158,12 @@ pub(crate) fn emit_unescape_error(
158158 "this is an isolated carriage return; consider checking your editor and \
159159 version control settings",
160160 ) ;
161+ } else if looks_like_quote ( c) {
162+ diag. help (
163+ format ! ( "{ec} is not an ascii quote, \
164+ but may look like one in some fonts.\n \
165+ consider writing it in its \
166+ escaped form for clarity.") ) ;
161167 } else {
162168 if mode == Mode :: Str || mode == Mode :: Char {
163169 diag. span_suggestion (
@@ -295,3 +301,23 @@ pub(crate) fn escaped_char(c: char) -> String {
295301 _ => c. escape_default ( ) . to_string ( ) ,
296302 }
297303}
304+
305+ /// Returns true if `c` may look identical to `"` in some fonts.
306+ fn looks_like_quote ( c : char ) -> bool {
307+ // list of homoglyphs generated using the following wikidata query:
308+ // SELECT ?u WHERE {
309+ // wd:Q87495536 wdt:P2444+ ?c.
310+ // ?c wdt:P4213 ?u.
311+ // }
312+ match c {
313+ '\u{2033}' |
314+ '\u{02BA}' |
315+ '\u{02DD}' |
316+ '\u{030B}' |
317+ '\u{030E}' |
318+ '\u{05F4}' |
319+ '\u{201C}' |
320+ '\u{201D}' => true ,
321+ _ => false ,
322+ }
323+ }
Original file line number Diff line number Diff line change 1+ fn main ( ) {
2+ dbg ! ( "since when is \“ THIS\” not allowed in a string literal" ) ;
3+ }
Original file line number Diff line number Diff line change 1+ error: unknown character escape: `\u{201c}`
2+ --> $DIR/unicode-quote.rs:2:26
3+ |
4+ LL | dbg!("since when is \“THIS\” not allowed in a string literal");
5+ | ^ unknown character escape
6+ |
7+ = help: \u{201c} is not an ascii quote, but may look like one in some fonts.
8+ consider writing it in its escaped form for clarity.
9+
10+ error: unknown character escape: `\u{201d}`
11+ --> $DIR/unicode-quote.rs:2:32
12+ |
13+ LL | dbg!("since when is \“THIS\” not allowed in a string literal");
14+ | ^ unknown character escape
15+ |
16+ = help: \u{201d} is not an ascii quote, but may look like one in some fonts.
17+ consider writing it in its escaped form for clarity.
18+
19+ error: aborting due to 2 previous errors
20+
You can’t perform that action at this time.
0 commit comments