We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c056cbb commit bbc2056Copy full SHA for bbc2056
src/doc/trpl/patterns.md
@@ -23,6 +23,31 @@ match x {
23
24
This prints `one`.
25
26
+There’s one pitfall with patterns: like anything that introduces a new binding,
27
+they introduce shadowing. For example:
28
+
29
+```rust
30
+let x = 'x';
31
+let c = 'c';
32
33
+match c {
34
+ x => println!("x: {} c: {}", x, c),
35
+}
36
37
+println!("x: {}", x)
38
+```
39
40
+This prints:
41
42
+```text
43
+x: c c: c
44
+x: x
45
46
47
+In other words, `x =>` matches the pattern and introduces a new binding named
48
+`x` that’s in scope for the match arm. Because we already have a binding named
49
+`x`, this new `x` shadows it.
50
51
# Multiple patterns
52
53
You can match multiple patterns with `|`:
0 commit comments