Skip to content

Commit d76952f

Browse files
committed
give tip for unicode chars which might not be visible
1 parent 1603a70 commit d76952f

File tree

7 files changed

+22
-0
lines changed

7 files changed

+22
-0
lines changed

compiler/rustc_parse/src/lexer/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ impl<'a> StringReader<'a> {
322322
let token = unicode_chars::check_for_substitution(self, start, c, &mut err);
323323
if c == '\x00' {
324324
err.help("source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used");
325+
} else if let Ok(v) = &err.suggestions && v.len() == 0 && !c.is_ascii() {
326+
err.help(format!("Unicode character {} might not be visible when rendered", escaped_char(c)));
325327
}
326328
err.emit();
327329
token?

src/test/ui/fmt/incorrect-separator.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: unknown start of token: \u{326}
33
|
44
LL | format!("A number: {}" ̦ iter::once(42).next().unwrap());
55
| ^
6+
|
7+
= help: Unicode character \u{326} might not be visible when rendered
68

79
error: expected `,`, found `.`
810
--> $DIR/incorrect-separator.rs:7:27

src/test/ui/issues/issue-69130.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: unknown start of token: \u{a7}
33
|
44
LL | M (§& u8)}
55
| ^
6+
|
7+
= help: Unicode character \u{a7} might not be visible when rendered
68

79
error[E0106]: missing lifetime specifier
810
--> $DIR/issue-69130.rs:4:5

src/test/ui/lexer/lex-bad-token.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: unknown start of token: \u{25cf}
33
|
44
LL | ●
55
| ^
6+
|
7+
= help: Unicode character \u{25cf} might not be visible when rendered
68

79
error: aborting due to previous error
810

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
println!("hello {}"̣, 1);
3+
//~^ ERROR: unknown start of token: \u{323}
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: unknown start of token: \u{323}
2+
--> $DIR/lex-bad-unicode-char.rs:2:24
3+
|
4+
LL | println!("hello {}"̣, 1);
5+
| ^
6+
|
7+
= help: Unicode character \u{323} might not be visible when rendered
8+
9+
error: aborting due to previous error
10+
77 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)