本页尚未翻译,以下为英文原文。
#E0103: binding looks like a variant
A bare name in a pattern is a new variable that matches every value, unless it is exactly a variant of the matched enum. This name is a const or static, or is close to a variant's name, so it would bind everything. Write the variant's path, Color::Red, or compare in a guard: x if x == LIMIT.
nabi
const LIMIT: i32 = 10;
let n = 3;
match n {
LIMIT => println("at the limit"),
_ => println("below"),
}
error[E0103]: `LIMIT` here would be a new variable that matches every value, not the const `LIMIT` --> main.nabi:5:5 | 5 | LIMIT => println("at the limit"), | ^^^^^ | = help: to compare with the const, write `x if x == LIMIT`
Compare with the const in a guard:
nabi
const LIMIT: i32 = 10;
let n = 3;
match n {
m if m == LIMIT => println("at the limit"),
_ => println("below"),
}
below
Related: E0029 cannot find enum variant, E0099 unreachable match arm
Found a mistake? Edit this page on GitHub. Last updated