docs

你正在阅读 v0.1.0 的文档。Nabi 0.1.0 已不再提供支持。 最新版本:v0.1.3 →

本页尚未翻译,以下为英文原文。

#E0060: let .. else that does not diverge

The else block of let .. else runs when the pattern does not match, so it must leave the scope: end it with return, break, continue or 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 {
   |             ^^^^^^^^^^

Leave the function in the else block:

nabi
fn first(xs: List<i32>) -> i32 {
    let n = xs.first() else {
        return 0;
    };
    n
}
println(f"{first([])} {first([4])}");
0 4

Related: E0059 keyword outside its context, E0100 pattern does not fit the value's type

Found a mistake? Edit this page on GitHub. Last updated