E3018

E3018#

Bounds of range pattern must be constant, named constant or wildcard.

Erroneous example#

fn main {
  let a = 3
  match 0 {
    0..<a => println("Between 0 and 3") // Error: Bounds of range pattern must be constant, named constant or wildcard.
    _ => println("Not between 0 and 3")
  }
}

Suggestion#

You can either lift the variable a to a named constant:

const A = 3
fn main {
  match 0 {
    0..<A => println("Between 0 and 3")
    _ => println("Not between 0 and 3")
  }
}

Or, you can use the constant value directly:

fn main {
  match 0 {
    0..<3 => println("Between 0 and 3")
    _ => println("Not between 0 and 3")
  }
}

Or, you can use a wildcard:

fn main {
  let a = 3
  match 0 {
    0..<_ => println("Big than or equal to 0")
    _ => println("Less than 0")
  }
}

Notice, using wildcard alters the meaning of this range pattern.