Merge pull request #4122 from rust-lang/fix-inverted-shadowing

Fix more inverted uses of “shadowed”
This commit is contained in:
Chris Krycho
2024-12-02 09:22:15 -07:00
committed by GitHub

View File

@@ -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 cant combine these two conditions into `if let Ok(age) = age && age >
30`. The shadowed `age` we want to compare to 30 isnt 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 cant combine these two conditions into `if
let Ok(age) = age && age > 30`. The new `age` we want to compare to 30 isnt
valid until the new scope starts with the curly bracket.
The downside of using `if let` expressions is that the compiler doesnt check
for exhaustiveness, whereas with `match` expressions it does. If we omitted the