Skip to content

Commit

Permalink
Clarified shadowing example
Browse files Browse the repository at this point in the history
Added some additional descriptive sentences and changed x to an int in
the example
  • Loading branch information
Xmasreturns committed Dec 17, 2015
1 parent 6734dcc commit 2a23e4a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/doc/book/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ There’s one pitfall with patterns: like anything that introduces a new binding
they introduce shadowing. For example:

```rust
let x = 'x';
let x = 1;
let c = 'c';

match c {
Expand All @@ -41,12 +41,14 @@ This prints:

```text
x: c c: c
x: x
x: 1
```

In other words, `x =>` matches the pattern and introduces a new binding named
`x` that’s in scope for the match arm. Because we already have a binding named
`x`, this new `x` shadows it.
`x`. This new binding is in scope for the match arm and takes on the value of
`c`. Notice that the value of `x` outside the scope of the match has no bearing
on the value of `x` within it. Because we already have a binding named `x`, this
new `x` shadows it.

# Multiple patterns

Expand Down

0 comments on commit 2a23e4a

Please sign in to comment.