Sisu
E0126

Constant in a pattern

Error

Built from the repository at commit a8614dc.

A name in a pattern binds the value or names a variant; it never compares with a constant of that name.

Why

In some languages a constant in a pattern compares, and in others it binds a new name that hides the constant. Sisu does neither, so the reader never has to guess. Bind a name and compare it in a guard: n if n == LIMIT. A constant as a range bound gets no such help, since 0..=LIMIT is a range and n == LIMIT one value; write the bound as a literal.

Broken

const LIMIT = 9

fn main() {
    let n = match 9 {
        LIMIT => 1
        _ => 0
    }
    print(n)
}

What sisu says

error[E0126]: `LIMIT` is a constant; a pattern cannot compare with it
 --> E0126.sisu:5:9
  |
5 |         LIMIT => 1
  |         ^^^^^
  |
  = help: use a guard: `n if n == LIMIT`

sisu: 1 error
sisu: for more on a code, run `sisu explain <code>`: E0126

Fixed

const LIMIT = 9

fn main() {
    let n = match 9 {
        n if n == LIMIT => 1
        _ => 0
    }
    print(n)
}