#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 上編輯此頁 最後更新: