Skip to content

Commit 5ab52b7

Browse files
committed
Add example
1 parent 409e3b6 commit 5ab52b7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/statements.md

+11
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ The `else` block has to always diverge (evaluate to type `!`).
7373
If an `else` block is present, restrictions apply on the expression:
7474
It might not be a [_LazyBooleanExpression_], or end in a `}` token.
7575

76+
```rust
77+
let (mut v, w) = (vec![1, 2, 3], 42); // The bindings may be mut or const
78+
let Some(t) = v.pop() else { // Refutable patterns require an else block
79+
panic!(); // The else block has to diverge
80+
};
81+
let [u, v] = [v[0], v[1]] else { // This pattern is irrefutable, so the compiler
82+
// will lint as the else block is redundant.
83+
panic!();
84+
};
85+
```
86+
7687
## Expression statements
7788

7889
> **<sup>Syntax</sup>**\

0 commit comments

Comments
 (0)