Skip to content

Commit 3eacf00

Browse files
committed
Add example
1 parent 9df3a29 commit 3eacf00

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/statements.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ If the pattern does not match (this requires it to be refutable), the `else`
7575
block is executed.
7676
The `else` block must always diverge (evaluate to the [never type]).
7777

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

8091
> **<sup>Syntax</sup>**\

0 commit comments

Comments
 (0)