Error codes

E0028: misplaced &

In a terminal: auk explain E0028 prints this page.

On this page

&x only appears directly on a call argument, to pass x to a var parameter so the callee can change it. It isn't a reference or address-of operator, and it needs something assignable.

Wrong#

auk
fn main() {
  var xs = [1]
  let ys = &xs
  print(ys)
}

Fixed#

auk
fn main() {
  var xs = [1]
  let ys = xs
  print(ys)
}

Common causes#

  • Taking a reference as in Rust or C++: Auk copies values cheaply (copy-on-write).
  • & on something that isn't a variable, field or index: f(&g()).
  • & for logical and: write &&.

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