Error codes

E0032: let is a statement, not an expression

In a terminal: auk explain E0032 prints this page.

On this page

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#

auk
fn main() {
  print(let x = 1)
}

Fixed#

auk
fn main() {
  let x = 1
  print(x)
}

Common causes#

  • if let / while let from Rust or Swift: use match, x is pat, or let pat = x else { ... }.
  • Declaring a variable inside a call: put the binding on its own line first.

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page