docs

#E0083: 无效的枚举值

值枚举(V = n)只能有值变体,每个变体都有一个互不相同、能放进标签类型的常量。修正消息指出的变体。

nabi
enum Code { Ok = 0, Bad = 0 }
error[E0083]: `Code::Bad` and `Code::Ok` have the same value 0
  --> main.nabi:1:1
   |
 1 | enum Code { Ok = 0, Bad = 0 }
   | ^^^^

给每个变体一个自己的值:

nabi
enum Code { Ok = 0, Bad = 1 }
println(f"{Code::Bad as i32}");
1

相关错误码:E0094 无效的表示

发现错误? 在 GitHub 上编辑此页 最后更新: