Skip to content

Commit 086be2b

Browse files
authoredJan 25, 2022
Rollup merge of #93303 - compiler-errors:issue-93282, r=wesleywiser
Fix ICE when parsing bad turbofish with lifetime argument Generalize conditions where we suggest adding the turbofish operator, so we don't ICE during code like ```rust fn foo() { A<'a,> } ``` but instead suggest adding a turbofish. Fixes #93282
2 parents 04f915b + 37bed05 commit 086be2b

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed
 

‎compiler/rustc_parse/src/parser/diagnostics.rs

+12-18
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 self.check(&TokenKind::Semi) {
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ impl<'a> Parser<'a> {
14581458
self.parse_block_expr(label, lo, BlockCheckMode::Default, attrs)
14591459
} else if !ate_colon && (self.check(&TokenKind::Comma) || self.check(&TokenKind::Gt)) {
14601460
// We're probably inside of a `Path<'a>` that needs a turbofish, so suppress the
1461-
// "must be followed by a colon" error.
1461+
// "must be followed by a colon" error, and the "expected one of" error.
14621462
self.diagnostic().delay_span_bug(lo, "this label wasn't parsed correctly");
14631463
consume_colon = false;
14641464
Ok(self.mk_expr_err(lo))
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
f<'a,>
3+
//~^ ERROR expected
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: expected one of `.`, `:`, `;`, `?`, `for`, `loop`, `while`, `{`, `}`, or an operator, found `,`
2+
--> $DIR/issue-93282.rs:2:9
3+
|
4+
LL | f<'a,>
5+
| ^ expected one of 10 possible tokens
6+
|
7+
help: use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
8+
|
9+
LL | f::<'a,>
10+
| ++
11+
12+
error: aborting due to previous error
13+

0 commit comments

Comments
 (0)
Please sign in to comment.