Skip to content

Commit 7b47865

Browse files
authored
Merge pull request #1401 from saward/master
Add note for match guards to include catch-all
2 parents 1cce073 + 9b02990 commit 7b47865

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/flow_control/match/guard.md

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ fn main() {
1818
}
1919
```
2020

21+
Note that the compiler does not check arbitrary expressions for whether all
22+
possible conditions have been checked. Therefore, you must use the `_` pattern
23+
at the end.
24+
25+
```rust,editable
26+
fn main() {
27+
let number: u8 = 4;
28+
29+
match number {
30+
i if i == 0 => println!("Zero"),
31+
i if i > 0 => println!("Greater than zero"),
32+
_ => println!("Fell through"), // This should not be possible to reach
33+
}
34+
}
35+
```
36+
2137
### See also:
2238

2339
[Tuples](../../primitives/tuples.md)

0 commit comments

Comments
 (0)