Closed
Description
hashbrown::HashMap::get
returns a reference which has no significant drop.
I've see this on other methods like hashbrown::HashMap::get_mut
, the equivalent methods on std::collections::HashMap
don't seem to have this false positive.
Code
#![warn(if_let_rescope)]
#![allow(unused_variables)]
fn main() {
let h = hashbrown::HashMap::<u32, u32>::default();
if let Some(value) = h.get(&0) {
// do something
} else {
// do something else
}
}
Code in the playground.
Current output
warning: `if let` assigns a shorter lifetime since Edition 2024
--> src/main.rs:6:8
|
6 | if let Some(value) = h.get(&0) {
| ^^^^^^^^^^^^^^^^^^-^^^^^^^^
| |
| 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/main.rs:8:5
|
8 | } else {
| ^
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(if_let_rescope)]
| ^^^^^^^^^^^^^^
help: a `match` with a single arm can preserve the drop order up to Edition 2021
|
6 ~ match h.get(&0) { Some(value) => {
7 | // do something
8 ~ } _ => {
9 | // do something else
10~ }}
|
Metadata
Metadata
Assignees
Labels
Area: The 2024 editionArea: Lints (warnings about flaws in source code) such as unused_mut.Category: This is a bug.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.