Rollup merge of #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:
d1a0fa5ed3/compiler/rustc_parse/src/parser/mod.rs (L900-L901)

If parsing the item itself calls `expect_one_of`, then we will fatal because of #58903:
d1a0fa5ed3/compiler/rustc_parse/src/parser/mod.rs (L513-L516)

For `precise_capturing` feature I implemented, we do end up calling `expected_one_of`:
d1a0fa5ed3/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 #124195
This commit is contained in:
Matthias Krüger 2024-04-23 20:17:51 +02:00 committed by GitHub
commit afb6c4681a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 0 deletions

View file

@ -895,6 +895,7 @@ impl<'a> Parser<'a> {
}
// Attempt to keep parsing if it was an omitted separator.
self.last_unexpected_token_span = None;
match f(self) {
Ok(t) => {
// Parsed successfully, therefore most probably the code only