Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note for match guards to include catch-all #1401

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/flow_control/match/guard.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ fn main() {
}
```

Note that the compiler does not check arbitrary expressions for whether all
possible conditions have been checked. Therefore, you must use the `_` pattern
at the end.

```rust,editable
fn main() {
let number: u8 = 4;

match number {
i if i == 0 => println!("Zero"),
i if i > 0 => println!("Greater than zero"),
_ => println!("Fell through"), // This should not be possible to reach
}
}
```

### See also:

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