#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에서 이 페이지 고치기. 마지막 수정