File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 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
2727they introduce shadowing. For example:
2828
2929``` rust
30- let x = 'x' ;
30+ let x = 1 ;
3131let c = 'c' ;
3232
3333match c {
@@ -41,12 +41,14 @@ This prints:
4141
4242``` text
4343x: c c: c
44- x: x
44+ x: 1
4545```
4646
4747In 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.
5052
5153# Multiple patterns
5254
You can’t perform that action at this time.
0 commit comments