Skip to content

Commit 1487aa9

Browse files
committed
Add double-equals homoglyph
1 parent 3520bba commit 1487aa9

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

compiler/rustc_parse/src/lexer/unicode_chars.rs

+2
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ pub(crate) const UNICODE_ARRAY: &[(char, &str, &str)] = &[
296296
('〉', "Right Angle Bracket", ">"),
297297
('》', "Right Double Angle Bracket", ">"),
298298
('>', "Fullwidth Greater-Than Sign", ">"),
299+
('⩵', "Two Consecutive Equals Signs", "==")
299300
];
300301

301302
// FIXME: the lexer could be used to turn the ASCII version of unicode homoglyphs, instead of
@@ -325,6 +326,7 @@ const ASCII_ARRAY: &[(&str, &str, Option<token::TokenKind>)] = &[
325326
("+", "Plus Sign", Some(token::BinOp(token::Plus))),
326327
("<", "Less-Than Sign", Some(token::Lt)),
327328
("=", "Equals Sign", Some(token::Eq)),
329+
("==", "Double Equals Sign", Some(token::EqEq)),
328330
(">", "Greater-Than Sign", Some(token::Gt)),
329331
// FIXME: Literals are already lexed by this point, so we can't recover gracefully just by
330332
// spitting the correct token out.

tests/ui/parser/unicode-chars.rs

+3
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ fn main() {
66
//~^ ERROR unknown start of token: \u{a0}
77
//~^^ NOTE character appears 3 more times
88
//~^^^ HELP Unicode character ' ' (No-Break Space) looks like ' ' (Space), but it is not
9+
let _ = 12;
10+
//~^ ERROR unknown start of token
11+
//~^^ HELP Unicode character '⩵' (Two Consecutive Equals Signs) looks like '==' (Double Equals Sign), but it is not
912
}

tests/ui/parser/unicode-chars.stderr

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,16 @@ help: Unicode character ' ' (No-Break Space) looks like ' ' (Space), but it is
2121
LL | let x = 0;
2222
| ++++
2323

24-
error: aborting due to 2 previous errors
24+
error: unknown start of token: \u{2a75}
25+
--> $DIR/unicode-chars.rs:9:15
26+
|
27+
LL | let _ = 1 ⩵ 2;
28+
| ^
29+
|
30+
help: Unicode character '⩵' (Two Consecutive Equals Signs) looks like '==' (Double Equals Sign), but it is not
31+
|
32+
LL | let _ = 1 == 2;
33+
| ~~
34+
35+
error: aborting due to 3 previous errors
2536

0 commit comments

Comments
 (0)