Skip to content

let_and_return : false positive #1642

@wagnerf42

Description

@wagnerf42

false positive for let and return (possible linked to #848)
commented version works but generate clippy's warning.
given version does not compile:

error: `h` does not live long enough
 --> src/main.rs:9:1
  |
6 |     h.drain().map(|(_, v)| v).collect()
  |     - borrow occurs here
...
9 | }
  | ^ `h` dropped here while still borrowed
  |
  = note: values in a scope are dropped in the opposite order they are created

source code:

use std::collections::HashMap;
fn vecto() -> Vec<u32> {
    let mut h = HashMap::new();
    h.insert(1000, 3);
    h.insert(10000, 4);
    h.drain().map(|(_, v)| v).collect()
    //let r = h.drain().map(|(_, v)| v).collect();
    //r
}

fn main() {
    let v = vecto();
    println!("{:?}", v);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions