mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-28 11:38:01 +00:00
When encountering a bare assignment in a let-chain, suggest turning the
assignment into a `let` expression or an equality check.
```
error: expected expression, found `let` statement
--> $DIR/bad-if-let-suggestion.rs:5:8
|
LL | if let x = 1 && i = 2 {}
| ^^^^^^^^^
|
= note: only supported directly in conditions of `if` and `while` expressions
help: you might have meant to continue the let-chain
|
LL | if let x = 1 && let i = 2 {}
| +++
help: you might have meant to compare for equality
|
LL | if let x = 1 && i == 2 {}
| +
```
21 lines
464 B
Rust
21 lines
464 B
Rust
fn a() {
|
|
if let x = 1 && i = 2 {}
|
|
//~^ ERROR cannot find value `i` in this scope
|
|
//~| ERROR mismatched types
|
|
//~| ERROR expected expression, found `let` statement
|
|
}
|
|
|
|
fn b() {
|
|
if (i + j) = i {}
|
|
//~^ ERROR cannot find value `i` in this scope
|
|
//~| ERROR cannot find value `i` in this scope
|
|
//~| ERROR cannot find value `j` in this scope
|
|
}
|
|
|
|
fn c() {
|
|
if x[0] = 1 {}
|
|
//~^ ERROR cannot find value `x` in this scope
|
|
}
|
|
|
|
fn main() {}
|