Skip to content

Commit a090bb1

Browse files
Remove delayed bug when encountering label in bad turbofish
1 parent e7825f2 commit a090bb1

File tree

6 files changed

+45
-6
lines changed

6 files changed

+45
-6
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ impl<'a> Parser<'a> {
737737
"::".to_string(),
738738
Applicability::MaybeIncorrect,
739739
);
740-
if self.check(&TokenKind::Semi) {
740+
if matches!(self.token.kind, token::Semi | token::CloseDelim(_)) {
741741
turbo_err.emit();
742742
*expr = self.mk_expr_err(expr.span);
743743
return Ok(());

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,8 @@ impl<'a> Parser<'a> {
14481448
let lo = label.ident.span;
14491449
let label = Some(label);
14501450
let ate_colon = self.eat(&token::Colon);
1451+
let msg = "expected `while`, `for`, `loop` or `{` after a label";
1452+
14511453
let expr = if self.eat_keyword(kw::While) {
14521454
self.parse_while_expr(label, lo, attrs)
14531455
} else if self.eat_keyword(kw::For) {
@@ -1457,13 +1459,12 @@ impl<'a> Parser<'a> {
14571459
} else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() {
14581460
self.parse_block_expr(label, lo, BlockCheckMode::Default, attrs)
14591461
} else if !ate_colon && (self.check(&TokenKind::Comma) || self.check(&TokenKind::Gt)) {
1462+
self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit();
14601463
// We're probably inside of a `Path<'a>` that needs a turbofish, so suppress the
14611464
// "must be followed by a colon" error.
1462-
self.diagnostic().delay_span_bug(lo, "this label wasn't parsed correctly");
14631465
consume_colon = false;
14641466
Ok(self.mk_expr_err(lo))
14651467
} else {
1466-
let msg = "expected `while`, `for`, `loop` or `{` after a label";
14671468
self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit();
14681469
// Continue as an expression in an effort to recover on `'label: non_block_expr`.
14691470
self.parse_expr()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
f<'a,>
3+
//~^ ERROR expected
4+
//~| ERROR expected
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
7+
error: expected one of `.`, `:`, `;`, `?`, `for`, `loop`, `while`, `{`, `}`, or an operator, found `,`
8+
--> $DIR/issue-93282.rs:2:9
9+
|
10+
LL | f<'a,>
11+
| ^ expected one of 10 possible tokens
12+
|
13+
help: use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
14+
|
15+
LL | f::<'a,>
16+
| ++
17+
18+
error: aborting due to 2 previous errors
19+

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ fn main() {
2121

2222
let _ = f<'_, i8>();
2323
//~^ ERROR expected one of
24+
//~| ERROR expected
2425
//~| HELP use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
2526

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

3032
let _ = f<u8>;

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

Lines changed: 15 additions & 3 deletions
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)