diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-03-22 15:48:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-22 15:48:32 +0100 |
| commit | ea44d71f9bc76d2136e20553259d43f55f282db1 (patch) | |
| tree | 792b0ffe15867a29de688c9a94547b8bea5e8ff7 /src/test | |
| parent | 9890d9a9d0e76cecbb6cfad41c0901f248430877 (diff) | |
| parent | 4d30b92e3e57cf606a25c807a9e4ab2b7a4d1064 (diff) | |
| download | rust-ea44d71f9bc76d2136e20553259d43f55f282db1.tar.gz rust-ea44d71f9bc76d2136e20553259d43f55f282db1.zip | |
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
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/parser/recover-quantified-closure.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/parser/recover-quantified-closure.stderr | 16 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/test/ui/parser/recover-quantified-closure.rs b/src/test/ui/parser/recover-quantified-closure.rs new file mode 100644 index 00000000000..381324738f6 --- /dev/null +++ b/src/test/ui/parser/recover-quantified-closure.rs @@ -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`, `|` +} diff --git a/src/test/ui/parser/recover-quantified-closure.stderr b/src/test/ui/parser/recover-quantified-closure.stderr new file mode 100644 index 00000000000..0f011326516 --- /dev/null +++ b/src/test/ui/parser/recover-quantified-closure.stderr @@ -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 + |
