Auto merge of #101362 - compiler-errors:unnecessary-let, r=cjgillot
Suggest removing unnecessary prefix let in patterns Helps with #101291, though I think `@estebank` probably wants this: > Finally, I think it'd be nice if we could detect that we don't know for sure and "just" swallow the rest of the expression (find the next ; accounting for nested braces) or the end of the item (easier). ... to be implemented before we close that issue out completely.
This commit is contained in:
commit
a594044533
6 changed files with 74 additions and 1 deletions
11
src/test/ui/parser/unnecessary-let.rs
Normal file
11
src/test/ui/parser/unnecessary-let.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fn main() {
|
||||
for let x of [1, 2, 3] {}
|
||||
//~^ ERROR expected pattern, found `let`
|
||||
//~| ERROR missing `in` in `for` loop
|
||||
|
||||
match 1 {
|
||||
let 1 => {}
|
||||
//~^ ERROR expected pattern, found `let`
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
20
src/test/ui/parser/unnecessary-let.stderr
Normal file
20
src/test/ui/parser/unnecessary-let.stderr
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
error: expected pattern, found `let`
|
||||
--> $DIR/unnecessary-let.rs:2:9
|
||||
|
|
||||
LL | for let x of [1, 2, 3] {}
|
||||
| ^^^ help: remove the unnecessary `let` keyword
|
||||
|
||||
error: missing `in` in `for` loop
|
||||
--> $DIR/unnecessary-let.rs:2:15
|
||||
|
|
||||
LL | for let x of [1, 2, 3] {}
|
||||
| ^^ help: try using `in` here instead
|
||||
|
||||
error: expected pattern, found `let`
|
||||
--> $DIR/unnecessary-let.rs:7:9
|
||||
|
|
||||
LL | let 1 => {}
|
||||
| ^^^ help: remove the unnecessary `let` keyword
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue