docs

您正在閱讀 v0.1.2 的文件。Nabi 0.1.2 已停止支援。 最新版本:v0.1.3 →

本頁尚未翻譯,以下為英文原文。

#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