File tree 1 file changed +6
-4
lines changed
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ There’s one pitfall with patterns: like anything that introduces a new binding
27
27
they introduce shadowing. For example:
28
28
29
29
``` rust
30
- let x = 'x' ;
30
+ let x = 1 ;
31
31
let c = 'c' ;
32
32
33
33
match c {
@@ -41,12 +41,14 @@ This prints:
41
41
42
42
``` text
43
43
x: c c: c
44
- x: x
44
+ x: 1
45
45
```
46
46
47
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.
48
+ ` x ` . This new binding is in scope for the match arm and takes on the value of
49
+ ` c ` . Notice that the value of ` x ` outside the scope of the match has no bearing
50
+ on the value of ` x ` within it. Because we already have a binding named ` x ` , this
51
+ new ` x ` shadows it.
50
52
51
53
# Multiple patterns
52
54
You can’t perform that action at this time.
0 commit comments