本页尚未翻译,以下为英文原文。
#E0067: block statement leaves a value
A block-like statement (if, match, a block) gives a value but is not the last expression and has no ;. Add ; to drop the value, or bind it with 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 } | ^^
Make the if the function's value, or end it with ;:
nabi
fn pick(c: bool) -> i32 {
if c { 1 } else { 2 }
}
println(f"{pick(true)}");
1
Related: E0040 mismatched types
Found a mistake? Edit this page on GitHub. Last updated