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:
commit
ea44d71f9b
5 changed files with 66 additions and 14 deletions
10
src/test/ui/parser/recover-quantified-closure.rs
Normal file
10
src/test/ui/parser/recover-quantified-closure.rs
Normal 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`, `|`
|
||||
}
|
||||
16
src/test/ui/parser/recover-quantified-closure.stderr
Normal file
16
src/test/ui/parser/recover-quantified-closure.stderr
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue