-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change how
for (x in foo) {}
is handled
Use the same approach used for match arm patterns.
- Loading branch information
Showing
10 changed files
with
138 additions
and
81 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
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
15 changes: 15 additions & 0 deletions
15
tests/ui/parser/recover/recover-for-loop-parens-around-head.fixed
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,15 @@ | ||
// run-rustfix | ||
// Here we test that the parser is able to recover in a situation like | ||
// `for ( $pat in $expr )` since that is familiar syntax in other languages. | ||
// Instead we suggest that the user writes `for $pat in $expr`. | ||
|
||
#![deny(unused)] // Make sure we don't trigger `unused_parens`. | ||
|
||
fn main() { | ||
let vec = vec![1, 2, 3]; | ||
|
||
for _elem in vec { | ||
//~^ ERROR unexpected parentheses surrounding `for` loop head | ||
const _RECOVERY_WITNESS: u32 = 0u32; //~ ERROR mismatched types | ||
} | ||
} |
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
28 changes: 23 additions & 5 deletions
28
tests/ui/parser/recover/recover-for-loop-parens-around-head.stderr
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 |
---|---|---|
@@ -1,8 +1,26 @@ | ||
error: expected one of `)`, `,`, `@`, or `|`, found keyword `in` | ||
--> $DIR/recover-for-loop-parens-around-head.rs:10:16 | ||
error: unexpected parentheses surrounding `for` loop head | ||
--> $DIR/recover-for-loop-parens-around-head.rs:11:9 | ||
| | ||
LL | for ( elem in vec ) { | ||
| ^^ expected one of `)`, `,`, `@`, or `|` | ||
LL | for ( _elem in vec ) { | ||
| ^ ^ | ||
| | ||
help: remove parentheses in `for` loop | ||
| | ||
LL - for ( _elem in vec ) { | ||
LL + for _elem in vec { | ||
| | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/recover-for-loop-parens-around-head.rs:13:40 | ||
| | ||
LL | const _RECOVERY_WITNESS: u32 = 0u8; | ||
| ^^^ expected `u32`, found `u8` | ||
| | ||
help: change the type of the numeric literal from `u8` to `u32` | ||
| | ||
LL | const _RECOVERY_WITNESS: u32 = 0u32; | ||
| ~~~ | ||
|
||
error: aborting due to previous error | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |