Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarified shadowing example #30447

Merged
merged 1 commit into from
Dec 18, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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