Skip to content

Commit

Permalink
Rollup merge of rust-lang#93595 - compiler-errors:ice-on-lifetime-arg…
Browse files Browse the repository at this point in the history
…, 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)
  • Loading branch information
matthiaskrgr committed Feb 12, 2022
2 parents 22d3784 + 5be9e79 commit 4241233
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,9 +1457,9 @@ impl<'a> Parser<'a> {
} else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() {
self.parse_block_expr(label, lo, BlockCheckMode::Default, attrs)
} else if !ate_colon && (self.check(&TokenKind::Comma) || self.check(&TokenKind::Gt)) {
// We're probably inside of a `Path<'a>` that needs a turbofish, so suppress the
// "must be followed by a colon" error, and the "expected one of" error.
self.diagnostic().delay_span_bug(lo, "this label wasn't parsed correctly");
// We're probably inside of a `Path<'a>` that needs a turbofish
let msg = "expected `while`, `for`, `loop` or `{` after a label";
self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit();
consume_colon = false;
Ok(self.mk_expr_err(lo))
} else {
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/parser/issues/issue-93282.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
fn main() {
f<'a,>
//~^ ERROR expected
//~| ERROR expected
}

fn bar(a: usize, b: usize) -> usize {
a + b
}

fn foo() {
let x = 1;
bar('y, x);
//~^ ERROR expected
}
14 changes: 13 additions & 1 deletion src/test/ui/parser/issues/issue-93282.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
error: expected `while`, `for`, `loop` or `{` after a label
--> $DIR/issue-93282.rs:2:9
|
LL | f<'a,>
| ^ expected `while`, `for`, `loop` or `{` after a label

error: expected one of `.`, `:`, `;`, `?`, `for`, `loop`, `while`, `{`, `}`, or an operator, found `,`
--> $DIR/issue-93282.rs:2:9
|
Expand All @@ -9,5 +15,11 @@ help: use `::<...>` instead of `<...>` to specify lifetime, type, or const argum
LL | f::<'a,>
| ++

error: aborting due to previous error
error: expected `while`, `for`, `loop` or `{` after a label
--> $DIR/issue-93282.rs:13:11
|
LL | bar('y, x);
| ^ expected `while`, `for`, `loop` or `{` after a label

error: aborting due to 3 previous errors

2 changes: 2 additions & 0 deletions src/test/ui/parser/require-parens-for-chained-comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ fn main() {
let _ = f<'_, i8>();
//~^ ERROR expected one of
//~| HELP use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
//~| ERROR expected

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

let _ = f<u8>;
//~^ ERROR comparison operators cannot be chained
Expand Down
18 changes: 15 additions & 3 deletions src/test/ui/parser/require-parens-for-chained-comparison.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ help: use `::<...>` instead of `<...>` to specify lifetime, type, or const argum
LL | let _ = f::<u8, i8>();
| ++

error: expected `while`, `for`, `loop` or `{` after a label
--> $DIR/require-parens-for-chained-comparison.rs:22:17
|
LL | let _ = f<'_, i8>();
| ^ expected `while`, `for`, `loop` or `{` after a label

error: expected one of `.`, `:`, `;`, `?`, `else`, `for`, `loop`, `while`, `{`, or an operator, found `,`
--> $DIR/require-parens-for-chained-comparison.rs:22:17
|
Expand All @@ -64,8 +70,14 @@ help: use `::<...>` instead of `<...>` to specify lifetime, type, or const argum
LL | let _ = f::<'_, i8>();
| ++

error: expected `while`, `for`, `loop` or `{` after a label
--> $DIR/require-parens-for-chained-comparison.rs:27:9
|
LL | f<'_>();
| ^ expected `while`, `for`, `loop` or `{` after a label

error: comparison operators cannot be chained
--> $DIR/require-parens-for-chained-comparison.rs:26:6
--> $DIR/require-parens-for-chained-comparison.rs:27:6
|
LL | f<'_>();
| ^ ^
Expand All @@ -76,13 +88,13 @@ LL | f::<'_>();
| ++

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

error: aborting due to 8 previous errors
error: aborting due to 10 previous errors

0 comments on commit 4241233

Please sign in to comment.