diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2015-06-09 17:24:43 -0400 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2015-06-09 17:24:43 -0400 |
| commit | 67bb4e935614a4d961e8caf1757e2d51fa8422da (patch) | |
| tree | 1dadcd1e58793eb4695494653fb4ebfe20a3322d | |
| parent | c7de6aa3420df3ab84f0a1df893c4da88abb1393 (diff) | |
| parent | a0b08f387b5f383fb4a135a4cd68f0d3842743d2 (diff) | |
Rollup merge of #26129 - steveklabnik:gh26012, r=brson
Fixes #26012
| -rw-r--r-- | src/doc/trpl/patterns.md | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/doc/trpl/patterns.md b/src/doc/trpl/patterns.md index 93df0f19e8e..0f356d75abc 100644 --- a/src/doc/trpl/patterns.md +++ b/src/doc/trpl/patterns.md @@ -154,6 +154,31 @@ match x { This prints `Got an int!`. +If you’re using `if` with multiple patterns, the `if` applies to both sides: + +```rust +let x = 4; +let y = false; + +match x { + 4 | 5 if y => println!("yes"), + _ => println!("no"), +} +``` + +This prints `no`, because the `if` applies to the whole of `4 | 5`, and not to +just the `5`, In other words, the the precedence of `if` behaves like this: + +```text +(4 | 5) if y => ... +``` + +not this: + +```text +4 | (5 if y) => ... +``` + # ref and ref mut If you want to get a [reference][ref], use the `ref` keyword: |
