Skip to content

False postive for if-let-rescope on hashbrown::HashMap::get? #137411

Closed
@Imberflur

Description

@Imberflur

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

Labels

A-edition-2024Area: The 2024 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.I-edition-triagedIssue: This issue has been reviewed and triaged by the Edition team.L-false-positiveLint: False positive (should not have fired).L-if_let_rescopeLint: if_let_rescopeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions