-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
5 changed files
with
66 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`, `|` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|