Skip to content

Commit bba2788

Browse files
authored
Rollup merge of rust-lang#124169 - compiler-errors:parser-fatal, r=oli-obk
Don't fatal when calling `expect_one_of` when recovering arg in `parse_seq` In `parse_seq`, when parsing a sequence of token-separated items, if we don't see a separator, we try to parse another item eagerly in order to give a good diagnostic and recover from a missing separator: https://github.com/rust-lang/rust/blob/d1a0fa5ed3ffe52d72f761d3c95cbeb0a9cdfe66/compiler/rustc_parse/src/parser/mod.rs#L900-L901 If parsing the item itself calls `expect_one_of`, then we will fatal because of rust-lang#58903: https://github.com/rust-lang/rust/blob/d1a0fa5ed3ffe52d72f761d3c95cbeb0a9cdfe66/compiler/rustc_parse/src/parser/mod.rs#L513-L516 For `precise_capturing` feature I implemented, we do end up calling `expected_one_of`: https://github.com/rust-lang/rust/blob/d1a0fa5ed3ffe52d72f761d3c95cbeb0a9cdfe66/compiler/rustc_parse/src/parser/ty.rs#L712-L714 This leads the compiler to fatal *before* having emitted the first error, leading to absolutely no useful information for the user about what happened in the parser. This PR makes it so that we stop doing that. Fixes rust-lang#124195
2 parents ba00abe + 2ef1552 commit bba2788

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Diff for: compiler/rustc_parse/src/parser/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@ impl<'a> Parser<'a> {
895895
}
896896

897897
// Attempt to keep parsing if it was an omitted separator.
898+
self.last_unexpected_token_span = None;
898899
match f(self) {
899900
Ok(t) => {
900901
// Parsed successfully, therefore most probably the code only
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// We used to fatal error without any useful diagnostic when we had an unexpected
2+
// token due to a strange interaction between the sequence parsing code and the
3+
// param/lifetime parsing code.
4+
5+
fn hello() -> impl use<'a {}> Sized {}
6+
//~^ ERROR expected one of `,` or `>`, found `{`
7+
//~| ERROR expected item, found `>`
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: expected one of `,` or `>`, found `{`
2+
--> $DIR/unexpected-token.rs:5:27
3+
|
4+
LL | fn hello() -> impl use<'a {}> Sized {}
5+
| ^ expected one of `,` or `>`
6+
7+
error: expected item, found `>`
8+
--> $DIR/unexpected-token.rs:5:29
9+
|
10+
LL | fn hello() -> impl use<'a {}> Sized {}
11+
| ^ expected item
12+
|
13+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
14+
15+
error: aborting due to 2 previous errors
16+

0 commit comments

Comments
 (0)