Skip to content

Commit 97fae38

Browse files
authored
Rollup merge of #111181 - bvanjoi:fix-issue-111148, r=davidtwco
fix(parse): return unpected when current token is EOF close #111148 #111148 panic occurred because [FatalError.raise()](https://github.com/bvanjoi/rust/blob/master/compiler/rustc_parse/src/parser/mod.rs#LL540C3-L540C3) was encountered which caused by `Eof` and `Pound`(the last token) had same span, when parsing `#` in `fn a<<i<Y<w<>#`. <img width="825" alt="image" src="https://user-images.githubusercontent.com/30187863/236612589-9e2c6a0b-18cd-408c-b636-c12a51cbcf1c.png"> There are a few ways to solve this problem: - Change the action assign for [self.last_unexpected_token_span](https://github.com/rust-lang/rust/blob/master/compiler/rustc_parse/src/parser/diagnostics.rs#L592), for example, if current token is `Eof`, then return Error directly. - Avoid triggering the `FatalError` when the current token is `Eof`. I have chosen the second option because executing `expected_one_of_not_found` when the token is `Eof` but not in `ediable` seems reasonable.
2 parents 0b300a7 + 272dc5a commit 97fae38

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

compiler/rustc_parse/src/parser/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,9 @@ impl<'a> Parser<'a> {
536536
} else if inedible.contains(&self.token.kind) {
537537
// leave it in the input
538538
Ok(false)
539-
} else if self.last_unexpected_token_span == Some(self.token.span) {
539+
} else if self.token.kind != token::Eof
540+
&& self.last_unexpected_token_span == Some(self.token.span)
541+
{
540542
FatalError.raise();
541543
} else {
542544
self.expected_one_of_not_found(edible, inedible)
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fn a<<i<Y<w<>#
2+
//~^ ERROR expected one of `#`, `>`, `const`, identifier, or lifetime, found `<`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `#`, `>`, `const`, identifier, or lifetime, found `<`
2+
--> $DIR/issue-111148.rs:1:6
3+
|
4+
LL | fn a<<i<Y<w<>#
5+
| ^ expected one of `#`, `>`, `const`, identifier, or lifetime
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)