Skip to content

Commit 4241233

Browse files
authored
Rollup merge of rust-lang#93595 - compiler-errors:ice-on-lifetime-arg, r=jackh726
fix ICE when parsing lifetime as function argument I don't really like this, but we basically need to emit an error instead of just delaying an bug, because there are too many places in the AST that aren't covered by my previous PRs... cc: rust-lang#93282 (comment)
2 parents 22d3784 + 5be9e79 commit 4241233

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

compiler/rustc_parse/src/parser/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1457,9 +1457,9 @@ impl<'a> Parser<'a> {
14571457
} else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() {
14581458
self.parse_block_expr(label, lo, BlockCheckMode::Default, attrs)
14591459
} else if !ate_colon && (self.check(&TokenKind::Comma) || self.check(&TokenKind::Gt)) {
1460-
// We're probably inside of a `Path<'a>` that needs a turbofish, so suppress the
1461-
// "must be followed by a colon" error, and the "expected one of" error.
1462-
self.diagnostic().delay_span_bug(lo, "this label wasn't parsed correctly");
1460+
// We're probably inside of a `Path<'a>` that needs a turbofish
1461+
let msg = "expected `while`, `for`, `loop` or `{` after a label";
1462+
self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit();
14631463
consume_colon = false;
14641464
Ok(self.mk_expr_err(lo))
14651465
} else {
+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
fn main() {
22
f<'a,>
33
//~^ ERROR expected
4+
//~| ERROR expected
5+
}
6+
7+
fn bar(a: usize, b: usize) -> usize {
8+
a + b
9+
}
10+
11+
fn foo() {
12+
let x = 1;
13+
bar('y, x);
14+
//~^ ERROR expected
415
}

src/test/ui/parser/issues/issue-93282.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error: expected `while`, `for`, `loop` or `{` after a label
2+
--> $DIR/issue-93282.rs:2:9
3+
|
4+
LL | f<'a,>
5+
| ^ expected `while`, `for`, `loop` or `{` after a label
6+
17
error: expected one of `.`, `:`, `;`, `?`, `for`, `loop`, `while`, `{`, `}`, or an operator, found `,`
28
--> $DIR/issue-93282.rs:2:9
39
|
@@ -9,5 +15,11 @@ help: use `::<...>` instead of `<...>` to specify lifetime, type, or const argum
915
LL | f::<'a,>
1016
| ++
1117

12-
error: aborting due to previous error
18+
error: expected `while`, `for`, `loop` or `{` after a label
19+
--> $DIR/issue-93282.rs:13:11
20+
|
21+
LL | bar('y, x);
22+
| ^ expected `while`, `for`, `loop` or `{` after a label
23+
24+
error: aborting due to 3 previous errors
1325

src/test/ui/parser/require-parens-for-chained-comparison.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ fn main() {
2222
let _ = f<'_, i8>();
2323
//~^ ERROR expected one of
2424
//~| HELP use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
25+
//~| ERROR expected
2526

2627
f<'_>();
2728
//~^ comparison operators cannot be chained
2829
//~| HELP use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
30+
//~| ERROR expected
2931

3032
let _ = f<u8>;
3133
//~^ ERROR comparison operators cannot be chained

src/test/ui/parser/require-parens-for-chained-comparison.stderr

+15-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ help: use `::<...>` instead of `<...>` to specify lifetime, type, or const argum
5353
LL | let _ = f::<u8, i8>();
5454
| ++
5555

56+
error: expected `while`, `for`, `loop` or `{` after a label
57+
--> $DIR/require-parens-for-chained-comparison.rs:22:17
58+
|
59+
LL | let _ = f<'_, i8>();
60+
| ^ expected `while`, `for`, `loop` or `{` after a label
61+
5662
error: expected one of `.`, `:`, `;`, `?`, `else`, `for`, `loop`, `while`, `{`, or an operator, found `,`
5763
--> $DIR/require-parens-for-chained-comparison.rs:22:17
5864
|
@@ -64,8 +70,14 @@ help: use `::<...>` instead of `<...>` to specify lifetime, type, or const argum
6470
LL | let _ = f::<'_, i8>();
6571
| ++
6672

73+
error: expected `while`, `for`, `loop` or `{` after a label
74+
--> $DIR/require-parens-for-chained-comparison.rs:27:9
75+
|
76+
LL | f<'_>();
77+
| ^ expected `while`, `for`, `loop` or `{` after a label
78+
6779
error: comparison operators cannot be chained
68-
--> $DIR/require-parens-for-chained-comparison.rs:26:6
80+
--> $DIR/require-parens-for-chained-comparison.rs:27:6
6981
|
7082
LL | f<'_>();
7183
| ^ ^
@@ -76,13 +88,13 @@ LL | f::<'_>();
7688
| ++
7789

7890
error: comparison operators cannot be chained
79-
--> $DIR/require-parens-for-chained-comparison.rs:30:14
91+
--> $DIR/require-parens-for-chained-comparison.rs:32:14
8092
|
8193
LL | let _ = f<u8>;
8294
| ^ ^
8395
|
8496
= help: use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
8597
= help: or use `(...)` if you meant to specify fn arguments
8698

87-
error: aborting due to 8 previous errors
99+
error: aborting due to 10 previous errors
88100

0 commit comments

Comments
 (0)