Open
Description
Coming from #133167 (comment) and from this new forum thread, my takeaway of some remaining clear false positives is:
-
if the
if let
matches on an enum and only some enum variant(s) have fields with potentially-significant destructor, but those are exhaustively matched in the non-else
case of theif let
, then there can be no actual change in behavior, because theelse
case is only reached in case the drop is not significant -
in the case of
cargo-edit
, this wasif let Some(…irrefutable…) = expr
on anOption<T>
-
in the urlo thread, I’ve identified the case of
if let Err(…irrefutable…)
on aResult<(), E>
Here’s a simple repro for an Option
case:
Code
#![allow(unused)]
#![warn(if_let_rescope)]
struct Struct;
impl Drop for Struct {
fn drop(&mut self) {}
}
fn f(option_s: Option<Struct>) {
if let Some(s) = option_s {
// …
} else {
// …
}
}
Here’s the code in the playground.
Current output
warning: `if let` assigns a shorter lifetime since Edition 2024
--> src/lib.rs:10:8
|
10 | if let Some(s) = option_s {
| ^^^^^^^^^^^^^^--------
| |
| this value has a significant drop implementation which may observe a major change in drop order and requires your discretion
|
= warning: this changes meaning in Rust 2024
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>
help: the value is now dropped here in Edition 2024
--> src/lib.rs:12:5
|
12 | } else {
| ^
note: the lint level is defined here
--> src/lib.rs:2:9
|
2 | #![warn(if_let_rescope)]
| ^^^^^^^^^^^^^^
help: a `match` with a single arm can preserve the drop order up to Edition 2021
|
10 ~ match option_s { Some(s) => {
11 | // …
12 ~ } _ => {
13 | // …
14 ~ }}
|
@rustbot label A-edition-2024, A-lints, L-if_let_rescope, C-enhancement
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: The 2024 editionArea: Lints (warnings about flaws in source code) such as unused_mut.Category: An issue proposing an enhancement or a PR with one.Issue: This issue has been reviewed and triaged by the Edition team.Lint: False positive (should not have fired).Lint: if_let_rescopeRelevant to the compiler team, which will review and decide on the PR/issue.