Make the parser TokenStream more resilient after mismatched delimiter recovery
This commit is contained in:
parent
4bc1ce7bdb
commit
5b3b6b8d00
@ -7670,6 +7670,9 @@ impl<'a> Parser<'a> {
|
||||
let ret = f(self);
|
||||
let last_token = if self.token_cursor.stack.len() == prev {
|
||||
&mut self.token_cursor.frame.last_token
|
||||
} else if self.token_cursor.stack.is_empty() {//&& !self.unclosed_delims.is_empty() {
|
||||
// This can happen with mismatched delimiters (#62881)
|
||||
return Ok((ret?, TokenStream::new(vec![])));
|
||||
} else {
|
||||
&mut self.token_cursor.stack[prev].last_token
|
||||
};
|
||||
|
6
src/test/ui/issues/issue-62881.rs
Normal file
6
src/test/ui/issues/issue-62881.rs
Normal file
@ -0,0 +1,6 @@
|
||||
fn main() {}
|
||||
|
||||
fn f() -> isize { fn f() -> isize {} pub f<
|
||||
//~^ ERROR missing `fn` or `struct` for function or struct definition
|
||||
//~| ERROR mismatched types
|
||||
//~ ERROR this file contains an un-closed delimiter
|
29
src/test/ui/issues/issue-62881.stderr
Normal file
29
src/test/ui/issues/issue-62881.stderr
Normal file
@ -0,0 +1,29 @@
|
||||
error: this file contains an un-closed delimiter
|
||||
--> $DIR/issue-62881.rs:6:53
|
||||
|
|
||||
LL | fn f() -> isize { fn f() -> isize {} pub f<
|
||||
| - un-closed delimiter
|
||||
...
|
||||
LL |
|
||||
| ^
|
||||
|
||||
error: missing `fn` or `struct` for function or struct definition
|
||||
--> $DIR/issue-62881.rs:3:41
|
||||
|
|
||||
LL | fn f() -> isize { fn f() -> isize {} pub f<
|
||||
| ^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-62881.rs:3:29
|
||||
|
|
||||
LL | fn f() -> isize { fn f() -> isize {} pub f<
|
||||
| - ^^^^^ expected isize, found ()
|
||||
| |
|
||||
| this function's body doesn't return
|
||||
|
|
||||
= note: expected type `isize`
|
||||
found type `()`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
x
Reference in New Issue
Block a user