let and var introduce bindings in a block; they don't produce a value, so they can't appear
inside another expression such as a call argument or a condition.
Wrong#
fn main() {
print(let x = 1)
}Fixed#
fn main() {
let x = 1
print(x)
}Common causes#
if let/while letfrom Rust or Swift: usematch,x is pat, orlet pat = x else { ... }.- Declaring a variable inside a call: put the binding on its own line first.