Skip to content

Commit 4f8b32c

Browse files
committed
Rollup merge of rust-lang#30447 - Xmasreturns:Docu, r=steveklabnik
Added sentences for description of code and changed x in the example to an int
2 parents e916676 + 2a23e4a commit 4f8b32c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/doc/book/patterns.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ There’s one pitfall with patterns: like anything that introduces a new binding
2727
they introduce shadowing. For example:
2828

2929
```rust
30-
let x = 'x';
30+
let x = 1;
3131
let c = 'c';
3232

3333
match c {
@@ -41,12 +41,14 @@ This prints:
4141

4242
```text
4343
x: c c: c
44-
x: x
44+
x: 1
4545
```
4646

4747
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.
5052

5153
# Multiple patterns
5254

0 commit comments

Comments
 (0)