E0051
Error
if let or while let on a value that is not an enum or optional
Errorif let and while let test an enum against a pattern, or unwrap an optional: they run their block with the names the pattern binds, when the value matches.
Why
A value that is not optional is always there, so there is nothing to test. Use the value itself.
Broken
fn main() {
let n = 5
if let x = n {
print(x)
}
}
What sisu says
error[E0051]: `if let` needs an enum or an optional; this is `i64` --> E0051.sisu:3:16 | 3 | if let x = n { | ^ | = help: compare with `==` sisu: 1 error sisu: for more on a code, run `sisu explain <code>`: E0051
Fixed
fn main() {
let n: i64? = 5
if let x = n {
print(x)
}
}
Sisu