From 2ef15523c15758ae00aa192de7077fd36fa61315 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 19 Apr 2024 13:12:12 -0400 Subject: [PATCH] Don't fatal when calling expect_one_of when recovering arg in parse_seq --- compiler/rustc_parse/src/parser/mod.rs | 1 + .../precise-capturing/unexpected-token.rs | 9 +++++++++ .../precise-capturing/unexpected-token.stderr | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 tests/ui/impl-trait/precise-capturing/unexpected-token.rs create mode 100644 tests/ui/impl-trait/precise-capturing/unexpected-token.stderr diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 4a996f89a9a..33efdc84417 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -898,6 +898,7 @@ fn parse_seq_to_before_tokens( } // 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 diff --git a/tests/ui/impl-trait/precise-capturing/unexpected-token.rs b/tests/ui/impl-trait/precise-capturing/unexpected-token.rs new file mode 100644 index 00000000000..39c8c0def6b --- /dev/null +++ b/tests/ui/impl-trait/precise-capturing/unexpected-token.rs @@ -0,0 +1,9 @@ +// We used to fatal error without any useful diagnostic when we had an unexpected +// token due to a strange interaction between the sequence parsing code and the +// param/lifetime parsing code. + +fn hello() -> impl use<'a {}> Sized {} +//~^ ERROR expected one of `,` or `>`, found `{` +//~| ERROR expected item, found `>` + +fn main() {} diff --git a/tests/ui/impl-trait/precise-capturing/unexpected-token.stderr b/tests/ui/impl-trait/precise-capturing/unexpected-token.stderr new file mode 100644 index 00000000000..989c479b248 --- /dev/null +++ b/tests/ui/impl-trait/precise-capturing/unexpected-token.stderr @@ -0,0 +1,16 @@ +error: expected one of `,` or `>`, found `{` + --> $DIR/unexpected-token.rs:5:27 + | +LL | fn hello() -> impl use<'a {}> Sized {} + | ^ expected one of `,` or `>` + +error: expected item, found `>` + --> $DIR/unexpected-token.rs:5:29 + | +LL | fn hello() -> impl use<'a {}> Sized {} + | ^ expected item + | + = note: for a full list of items that can appear in modules, see + +error: aborting due to 2 previous errors +