Tweak invalid fn header and body parsing

* Recover empty `fn` bodies when encountering `}`
* Recover trailing `>` in return types
* Recover from non-type in array type `[<BAD TOKEN>; LEN]`
This commit is contained in:
Esteban Küber 2020-10-25 14:20:44 -07:00
parent 040f568815
commit ff61949860
7 changed files with 53 additions and 27 deletions

View file

@ -1,4 +1,3 @@
fn foo(a: [0; 1]) {} //~ ERROR expected type, found `0`
//~| ERROR expected one of `)`, `,`, `->`, `;`, `where`, or `{`, found `]`
fn main() {}

View file

@ -4,11 +4,5 @@ error: expected type, found `0`
LL | fn foo(a: [0; 1]) {}
| ^ expected type
error: expected one of `)`, `,`, `->`, `;`, `where`, or `{`, found `]`
--> $DIR/issue-39616.rs:1:16
|
LL | fn foo(a: [0; 1]) {}
| ^ expected one of `)`, `,`, `->`, `;`, `where`, or `{`
error: aborting due to 2 previous errors
error: aborting due to previous error

View file

@ -1,8 +1,9 @@
// Verify that '>' is not both expected and found at the same time, as it used
// to happen in #24780. For example, following should be an error:
// expected one of ..., `>`, ... found `>`
// expected one of ..., `>`, ... found `>`. No longer exactly this, but keeping for posterity.
fn foo() -> Vec<usize>> {
//~^ ERROR expected one of `!`, `+`, `::`, `;`, `where`, or `{`, found `>`
fn foo() -> Vec<usize>> { //~ ERROR unmatched angle bracket
Vec::new()
}
fn main() {}

View file

@ -1,8 +1,8 @@
error: expected one of `!`, `+`, `::`, `;`, `where`, or `{`, found `>`
error: unmatched angle bracket
--> $DIR/issue-24780.rs:5:23
|
LL | fn foo() -> Vec<usize>> {
| ^ expected one of `!`, `+`, `::`, `;`, `where`, or `{`
| ^^ help: remove extra angle bracket
error: aborting due to previous error

View file

@ -2,11 +2,9 @@ error: expected one of `->`, `;`, `where`, or `{`, found `}`
--> $DIR/issue-6610.rs:1:20
|
LL | trait Foo { fn a() }
| - ^
| | |
| | expected one of `->`, `;`, `where`, or `{`
| | the item list ends here
| while parsing this item list starting here
| - ^ expected one of `->`, `;`, `where`, or `{`
| |
| while parsing this `fn`
error: aborting due to previous error