docs

#E0067: 块语句留下了值

类似块的语句(if、match、块)给出了一个值,但它既不是最后一个表达式,也没有 ;。加上 ; 丢弃这个值,或者用 let 绑定它。

nabi
fn pick(c: bool) -> i32 {
    if c { 1 } else { 2 }
    3
}
error[E0067]: this block-like statement leaves a value of type `i64` without `;`: a statement must be `()` (add `;` to discard it, or make it the block's last expression)
  --> main.nabi:2:5
   |
 2 |     if c { 1 } else { 2 }
   |     ^^

让 if 成为函数的值,或者以 ; 结束它:

nabi
fn pick(c: bool) -> i32 {
    if c { 1 } else { 2 }
}
println(f"{pick(true)}");
1

相关错误码:E0040 类型不匹配

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