1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-08-08 08:22:52 +02:00

Fix typo in Matching Values section (#2832)

Given 

```
#[rustfmt::skip]
fn main() {
    let input = '1';
    match input {
        key if key.is_lowercase() => println!("Lowercase: {key}"),
        'q'                       => println!("Quitting"),
        'a' | 's' | 'w' | 'd'     => println!("Moving around"),
        '0'..='9'                 => println!("Number input"),
        _                         => println!("Something else"),
    }
}
```

the output will be

```
Number input
```

So in practice, failing the condition does result to the other arms if
the other arms are after that (if I'm reading this correctly).
This commit is contained in:
Vinh Tran
2025-07-27 12:52:11 -04:00
committed by GitHub
parent 697054c301
commit e157487e6e

View File

@ -43,7 +43,7 @@ Key Points:
wish to concisely express more complex ideas than patterns alone would allow. wish to concisely express more complex ideas than patterns alone would allow.
- They are not the same as separate `if` expression inside of the match arm. An - They are not the same as separate `if` expression inside of the match arm. An
`if` expression inside of the branch block (after `=>`) happens after the `if` expression inside of the branch block (after `=>`) happens after the
match arm is selected. Failing the `if` condition inside of that block won't match arm is selected. Failing the `if` condition inside of that block will
result in other arms of the original `match` expression being considered. result in other arms of the original `match` expression being considered.
- The condition defined in the guard applies to every expression in a pattern - The condition defined in the guard applies to every expression in a pattern
with an `|`. with an `|`.