Rollup merge of #70209 - Centril:recover-quant-closure, r=petrochenkov

parser: recover on `for<'a> |...| body` closures

When encountering `for` and `<` is 1 token ahead, interpret this as an explicitly quantified generic closure and recover, rather than attempting to parse a `for` loop. This provides both improved diagnostics as well as an insurance policy for the ability to use this as the syntax for generic closures in the future.

As requested by r? @eddyb
This commit is contained in:
Dylan DPC 2020-03-22 15:48:32 +01:00 committed by GitHub
commit ea44d71f9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 14 deletions

View file

@ -0,0 +1,10 @@
fn main() {
for<'a> |x: &'a u8| *x + 1;
//~^ ERROR cannot introduce explicit parameters for a closure
}
enum Foo { Bar }
fn foo(x: impl Iterator<Item = Foo>) {
for <Foo>::Bar in x {}
//~^ ERROR expected one of `move`, `static`, `|`
}

View file

@ -0,0 +1,16 @@
error: cannot introduce explicit parameters for a closure
--> $DIR/recover-quantified-closure.rs:2:5
|
LL | for<'a> |x: &'a u8| *x + 1;
| ^^^^^^^ ------------------ the parameters are attached to this closure
| |
| help: remove the parameters
error: expected one of `move`, `static`, `|`, or `||`, found `::`
--> $DIR/recover-quantified-closure.rs:8:14
|
LL | for <Foo>::Bar in x {}
| ^^ expected one of `move`, `static`, `|`, or `||`
error: aborting due to 2 previous errors