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

Fix more inverted uses of “shadowed” #4122

Merged
merged 1 commit into from
Dec 2, 2024
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: 5 additions & 5 deletions src/ch19-01-all-the-places-for-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ background color`.

You can see that `if let` can also introduce new variables which shadow existing
variables in the same way that `match` arms can: the line `if let Ok(age) = age`
introduces a new shadowed `age` variable that contains the value inside the `Ok`
variant. This means we need to place the `if age > 30` condition within that
block: we can’t combine these two conditions into `if let Ok(age) = age && age >
30`. The shadowed `age` we want to compare to 30 isn’t valid until the new scope
starts with the curly bracket.
introduces a new `age` variable that contains the value inside the `Ok` variant,
shadowing the existing `age` variable. This means we need to place the `if age >
30` condition within that block: we can’t combine these two conditions into `if
let Ok(age) = age && age > 30`. The new `age` we want to compare to 30 isn’t
valid until the new scope starts with the curly bracket.

The downside of using `if let` expressions is that the compiler doesn’t check
for exhaustiveness, whereas with `match` expressions it does. If we omitted the
Expand Down
Loading