bynk.parse.let_else_on_binding
Error An else follows a plain let name = … binding, which matches every value, so the else could never run.
else after a let says what the block does when the pattern does not match. A plain name matches every value, so this else could never run, and it is refused rather than ignored. To handle a failure, bind a pattern that can fail: Ok(x), Some(x), or a qualified variant such as Status.Pending. Otherwise drop the else.
Example
fn count(r: Result[Int, String]) -> Int { let n = r else { 0 } // ✗ a name always matches n}
fn count(r: Result[Int, String]) -> Int { let Ok(n) = r else { 0 } // ✓ an `Err` takes the `else` n}In the Book
See also
- The grammar rules it governs:
let_stmt,effect_let_stmt. - Every code in its category, Parser, on the diagnostic index.
bynk explain bynk.parse.let_else_on_bindingshows the same from the installed toolchain, without a network.