Skip to content

Commit

Permalink
Merge pull request #339 from ehuss/fix-if-let-rescope
Browse files Browse the repository at this point in the history
Fix `if_let_rescope` applicability
  • Loading branch information
traviscross authored Dec 3, 2024
2 parents f48b0e8 + 336191d commit 1286692
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/rust-2024/temporary-if-let-scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ fn f(value: &RwLock<Option<bool>>) {

In this particular example, that's probably not what you want due to the aforementioned deadlock! However, some scenarios may be assuming that the temporaries are held past the `else` clause, in which case you may want to retain the old behavior.

The `if_let_rescope` lint cannot deduce with complete confidence that the program semantics are preserved when the lifetime of such temporary values are shortened. For this reason, the suggestion from this lint is *not* automatically applied when running `cargo fix --edition`. It is recommended to manually inspect the warnings emitted when running `cargo fix --edition` and determine whether or not you need to apply the suggestion.
The [`if_let_rescope`] lint is part of the `rust-2024-compatibility` lint group which is included in the automatic edition migration. In order to migrate your code to be Rust 2024 Edition compatible, run:

```sh
cargo fix --edition
```

After the migration, it is recommended that you review all of the changes of `if let` to `match` and decide what is the behavior that you need with respect to when temporaries are dropped. If you determine that the change is unnecessary, then you can revert the change back to `if let`.

If you want to manually inspect these warnings without performing the edition migration, you can enable the lint with:

Expand Down

0 comments on commit 1286692

Please sign in to comment.