#E0060: 不會發散的 let .. else
let .. else 的 else 區塊在模式不符合時執行,所以它必須離開作用域:以 return、break、continue 或 throw 結束它。
nabi
fn first(xs: List<i32>) -> i32 {
let n = xs.first() else {
println("empty");
};
n
}
error[E0060]: the `else` block of `let ... else` must diverge (end in `return`, `break`, `continue` or `throw`) --> main.nabi:2:13 | 2 | let n = xs.first() else { | ^^^^^^^^^^
在 else 區塊中離開函式:
nabi
fn first(xs: List<i32>) -> i32 {
let n = xs.first() else {
return 0;
};
n
}
println(f"{first([])} {first([4])}");
0 4
相關錯誤碼:E0059 用在其語境之外的關鍵字、E0100 模式與值的型別不符
發現錯誤? 在 GitHub 上編輯此頁 最後更新: