docs

#E0102: or 模式的各選項繫結不同

a | b 的每個選項都必須以相同的型別繫結相同的名稱。請在每個選項中繫結相同的名稱,或給這個繫結一個和型別。

nabi
enum Shape { Circle(f64), Square(f64), Point }

fn size(s: Shape) -> f64 {
    match s {
        Shape::Circle(r) | Shape::Point => r,
        Shape::Square(w) => w,
    }
}
error[E0102]: or-pattern alternatives bind different name sets (alternative 1: missing `r`)
  --> main.nabi:5:28
   |
 5 |         Shape::Circle(r) | Shape::Point => r,
   |                            ^^^^^

在每個選項中繫結相同的名稱:

nabi
enum Shape { Circle(f64), Square(f64), Point }

fn size(s: Shape) -> f64 {
    match s {
        Shape::Circle(v) | Shape::Square(v) => v,
        Shape::Point => 0.0,
    }
}
println(f"{size(Shape::Square(2.0))}");
2

相關錯誤碼:E0098 不窮盡的 match、E0103 看起來像變體的繫結

發現錯誤? 在 GitHub 上編輯此頁 最後更新: