Skip to content

Commit 37bed05

Browse files
delay the bug once again, generalize turbofish suggestion
1 parent a090bb1 commit 37bed05

File tree

6 files changed

+19
-47
lines changed

6 files changed

+19
-47
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -731,28 +731,22 @@ impl<'a> Parser<'a> {
731731
match x {
732732
Ok((_, _, false)) => {
733733
if self.eat(&token::Gt) {
734-
let turbo_err = e.span_suggestion_verbose(
734+
e.span_suggestion_verbose(
735735
binop.span.shrink_to_lo(),
736736
TURBOFISH_SUGGESTION_STR,
737737
"::".to_string(),
738738
Applicability::MaybeIncorrect,
739-
);
740-
if matches!(self.token.kind, token::Semi | token::CloseDelim(_)) {
741-
turbo_err.emit();
742-
*expr = self.mk_expr_err(expr.span);
743-
return Ok(());
744-
} else {
745-
match self.parse_expr() {
746-
Ok(_) => {
747-
turbo_err.emit();
748-
*expr = self
749-
.mk_expr_err(expr.span.to(self.prev_token.span));
750-
return Ok(());
751-
}
752-
Err(mut err) => {
753-
turbo_err.cancel();
754-
err.cancel();
755-
}
739+
)
740+
.emit();
741+
match self.parse_expr() {
742+
Ok(_) => {
743+
*expr =
744+
self.mk_expr_err(expr.span.to(self.prev_token.span));
745+
return Ok(());
746+
}
747+
Err(mut err) => {
748+
*expr = self.mk_expr_err(expr.span);
749+
err.cancel();
756750
}
757751
}
758752
}

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,8 +1448,6 @@ 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-
14531451
let expr = if self.eat_keyword(kw::While) {
14541452
self.parse_while_expr(label, lo, attrs)
14551453
} else if self.eat_keyword(kw::For) {
@@ -1459,12 +1457,13 @@ impl<'a> Parser<'a> {
14591457
} else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() {
14601458
self.parse_block_expr(label, lo, BlockCheckMode::Default, attrs)
14611459
} 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();
14631460
// We're probably inside of a `Path<'a>` that needs a turbofish, so suppress the
1464-
// "must be followed by a colon" error.
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");
14651463
consume_colon = false;
14661464
Ok(self.mk_expr_err(lo))
14671465
} else {
1466+
let msg = "expected `while`, `for`, `loop` or `{` after a label";
14681467
self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit();
14691468
// Continue as an expression in an effort to recover on `'label: non_block_expr`.
14701469
self.parse_expr()
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
fn main() {
22
f<'a,>
33
//~^ ERROR expected
4-
//~| ERROR expected
54
}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
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-
71
error: expected one of `.`, `:`, `;`, `?`, `for`, `loop`, `while`, `{`, `}`, or an operator, found `,`
82
--> $DIR/issue-93282.rs:2:9
93
|
@@ -15,5 +9,5 @@ help: use `::<...>` instead of `<...>` to specify lifetime, type, or const argum
159
LL | f::<'a,>
1610
| ++
1711

18-
error: aborting due to 2 previous errors
12+
error: aborting due to previous error
1913

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

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

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

2726
f<'_>();
2827
//~^ comparison operators cannot be chained
29-
//~| ERROR expected
3028
//~| HELP use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
3129

3230
let _ = f<u8>;

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ 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-
6256
error: expected one of `.`, `:`, `;`, `?`, `else`, `for`, `loop`, `while`, `{`, or an operator, found `,`
6357
--> $DIR/require-parens-for-chained-comparison.rs:22:17
6458
|
@@ -70,14 +64,8 @@ help: use `::<...>` instead of `<...>` to specify lifetime, type, or const argum
7064
LL | let _ = f::<'_, i8>();
7165
| ++
7266

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-
7967
error: comparison operators cannot be chained
80-
--> $DIR/require-parens-for-chained-comparison.rs:27:6
68+
--> $DIR/require-parens-for-chained-comparison.rs:26:6
8169
|
8270
LL | f<'_>();
8371
| ^ ^
@@ -88,13 +76,13 @@ LL | f::<'_>();
8876
| ++
8977

9078
error: comparison operators cannot be chained
91-
--> $DIR/require-parens-for-chained-comparison.rs:32:14
79+
--> $DIR/require-parens-for-chained-comparison.rs:30:14
9280
|
9381
LL | let _ = f<u8>;
9482
| ^ ^
9583
|
9684
= help: use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
9785
= help: or use `(...)` if you meant to specify fn arguments
9886

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

0 commit comments

Comments
 (0)