From 272dc5a6d5967c0816564894b4fd86835a860d97 Mon Sep 17 00:00:00 2001 From: bohan Date: Thu, 4 May 2023 16:30:02 +0800 Subject: [PATCH] fix(parse): return unpected when current token is EOF --- compiler/rustc_parse/src/parser/mod.rs | 4 +++- tests/ui/parser/issues/issue-111148.rs | 2 ++ tests/ui/parser/issues/issue-111148.stderr | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/ui/parser/issues/issue-111148.rs create mode 100644 tests/ui/parser/issues/issue-111148.stderr diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 0c265d7af0e..c23420661fa 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -536,7 +536,9 @@ impl<'a> Parser<'a> { } else if inedible.contains(&self.token.kind) { // leave it in the input Ok(false) - } else if self.last_unexpected_token_span == Some(self.token.span) { + } else if self.token.kind != token::Eof + && self.last_unexpected_token_span == Some(self.token.span) + { FatalError.raise(); } else { self.expected_one_of_not_found(edible, inedible) diff --git a/tests/ui/parser/issues/issue-111148.rs b/tests/ui/parser/issues/issue-111148.rs new file mode 100644 index 00000000000..2502beab443 --- /dev/null +++ b/tests/ui/parser/issues/issue-111148.rs @@ -0,0 +1,2 @@ +fn a<# +//~^ ERROR expected one of `#`, `>`, `const`, identifier, or lifetime, found `<` diff --git a/tests/ui/parser/issues/issue-111148.stderr b/tests/ui/parser/issues/issue-111148.stderr new file mode 100644 index 00000000000..e6595a5cbcc --- /dev/null +++ b/tests/ui/parser/issues/issue-111148.stderr @@ -0,0 +1,8 @@ +error: expected one of `#`, `>`, `const`, identifier, or lifetime, found `<` + --> $DIR/issue-111148.rs:1:6 + | +LL | fn a<# + | ^ expected one of `#`, `>`, `const`, identifier, or lifetime + +error: aborting due to previous error +