Skip to content

Commit bb1c797

Browse files
committed
fix another ICE caused by improper unicode handling
1 parent ed43263 commit bb1c797

File tree

5 files changed

+82
-12
lines changed

5 files changed

+82
-12
lines changed

compiler/rustc_parse/src/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
249249
// lint for each `#` before the string.
250250
if !(
251251
start > self.start_pos &&
252-
self.str_from_to(start - BytePos(1), start) == "#"
252+
self.src.as_bytes()[self.src_index(start) - 1] == b'#'
253253
) {
254254
let span = self.mk_sp(start, self.pos);
255255
let space_span = n_start_hashes.map(|n_hashes| {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ edition:2021
2+
3+
macro_rules! demo2 {
4+
( $a:tt $b:tt ) => { println!("two tokens") };
5+
}
6+
7+
macro_rules! demo3 {
8+
( $a:tt $b:tt $c:tt ) => { println!("three tokens") };
9+
}
10+
11+
macro_rules! demo4 {
12+
( $a:tt $b:tt $c:tt $d:tt ) => { println!("four tokens") };
13+
}
14+
15+
fn main() {
16+
// Non-ascii identifiers
17+
demo2!(Ñ"foo"); //~ ERROR prefix `Ñ` is unknown
18+
demo4!(Ñ#""#); //~ ERROR prefix `Ñ` is unknown
19+
demo3!(🙃#"");
20+
//~^ ERROR prefix `🙃` is unknown
21+
//~| WARNING identifier contains an uncommon character
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
error: prefix `Ñ` is unknown
2+
--> $DIR/reserved-guarded-strings-lexing.rs:17:12
3+
|
4+
LL | demo2!(Ñ"foo");
5+
| ^ unknown prefix
6+
|
7+
= note: prefixed identifiers and literals are reserved since Rust 2021
8+
help: consider inserting whitespace here
9+
|
10+
LL | demo2!(Ñ "foo");
11+
| +
12+
13+
error: prefix `Ñ` is unknown
14+
--> $DIR/reserved-guarded-strings-lexing.rs:18:12
15+
|
16+
LL | demo4!(Ñ#""#);
17+
| ^ unknown prefix
18+
|
19+
= note: prefixed identifiers and literals are reserved since Rust 2021
20+
help: consider inserting whitespace here
21+
|
22+
LL | demo4!(Ñ #""#);
23+
| +
24+
25+
error: prefix `🙃` is unknown
26+
--> $DIR/reserved-guarded-strings-lexing.rs:19:12
27+
|
28+
LL | demo3!(🙃#"");
29+
| ^^ unknown prefix
30+
|
31+
= note: prefixed identifiers and literals are reserved since Rust 2021
32+
help: consider inserting whitespace here
33+
|
34+
LL | demo3!(🙃 #"");
35+
| +
36+
37+
warning: identifier contains an uncommon character: '🙃'
38+
--> $DIR/reserved-guarded-strings-lexing.rs:19:12
39+
|
40+
LL | demo3!(🙃#"");
41+
| ^^
42+
|
43+
= note: this character is included in the Unicode general security profile
44+
= note: `#[warn(uncommon_codepoints)]` on by default
45+
46+
error: aborting due to 3 previous errors; 1 warning emitted
47+

tests/ui/rust-2024/reserved-guarded-strings.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ fn main() {
4444
demo4!("foo"###);
4545

4646
demo2!(blah"xx"); //~ ERROR prefix `blah` is unknown
47-
demo2!(blah#"xx"#); //~ ERROR prefix `blah` is unknown
48-
//~^ ERROR invalid string literal
47+
demo2!(blah#"xx"#);
48+
//~^ ERROR prefix `blah` is unknown
49+
//~| ERROR invalid string literal
4950

5051
demo1!(#""); //~ ERROR invalid string literal
5152
demo1!(#""#); //~ ERROR invalid string literal

tests/ui/rust-2024/reserved-guarded-strings.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ LL | demo2!(blah# "xx"#);
3535
| +
3636

3737
error: invalid string literal
38-
--> $DIR/reserved-guarded-strings.rs:50:12
38+
--> $DIR/reserved-guarded-strings.rs:51:12
3939
|
4040
LL | demo1!(#"");
4141
| ^^^
@@ -47,7 +47,7 @@ LL | demo1!(# "");
4747
| +
4848

4949
error: invalid string literal
50-
--> $DIR/reserved-guarded-strings.rs:51:12
50+
--> $DIR/reserved-guarded-strings.rs:52:12
5151
|
5252
LL | demo1!(#""#);
5353
| ^^^^
@@ -59,7 +59,7 @@ LL | demo1!(# ""#);
5959
| +
6060

6161
error: invalid string literal
62-
--> $DIR/reserved-guarded-strings.rs:52:12
62+
--> $DIR/reserved-guarded-strings.rs:53:12
6363
|
6464
LL | demo1!(####"");
6565
| ^^^^^^
@@ -71,7 +71,7 @@ LL | demo1!(#### "");
7171
| +
7272

7373
error: invalid string literal
74-
--> $DIR/reserved-guarded-strings.rs:53:12
74+
--> $DIR/reserved-guarded-strings.rs:54:12
7575
|
7676
LL | demo1!(#"foo");
7777
| ^^^^^^
@@ -83,7 +83,7 @@ LL | demo1!(# "foo");
8383
| +
8484

8585
error: invalid string literal
86-
--> $DIR/reserved-guarded-strings.rs:54:12
86+
--> $DIR/reserved-guarded-strings.rs:55:12
8787
|
8888
LL | demo1!(###"foo");
8989
| ^^^^^^^^
@@ -95,7 +95,7 @@ LL | demo1!(### "foo");
9595
| +
9696

9797
error: invalid string literal
98-
--> $DIR/reserved-guarded-strings.rs:55:12
98+
--> $DIR/reserved-guarded-strings.rs:56:12
9999
|
100100
LL | demo1!(#"foo"#);
101101
| ^^^^^^^
@@ -107,7 +107,7 @@ LL | demo1!(# "foo"#);
107107
| +
108108

109109
error: invalid string literal
110-
--> $DIR/reserved-guarded-strings.rs:56:12
110+
--> $DIR/reserved-guarded-strings.rs:57:12
111111
|
112112
LL | demo1!(###"foo"#);
113113
| ^^^^^^^^^
@@ -119,7 +119,7 @@ LL | demo1!(### "foo"#);
119119
| +
120120

121121
error: invalid string literal
122-
--> $DIR/reserved-guarded-strings.rs:57:12
122+
--> $DIR/reserved-guarded-strings.rs:58:12
123123
|
124124
LL | demo1!(###"foo"##);
125125
| ^^^^^^^^^^
@@ -131,7 +131,7 @@ LL | demo1!(### "foo"##);
131131
| +
132132

133133
error: invalid string literal
134-
--> $DIR/reserved-guarded-strings.rs:58:12
134+
--> $DIR/reserved-guarded-strings.rs:59:12
135135
|
136136
LL | demo1!(###"foo"###);
137137
| ^^^^^^^^^^^

0 commit comments

Comments
 (0)