Skip to content

redundant_closure: suggest smaller item path #5549

@matthiaskrgr

Description

@matthiaskrgr
use std::collections::HashMap;
fn main() {
    let mut map: HashMap<&str, Vec<i32>> = HashMap::new();

    map.entry("bar").or_insert_with(|| vec![]);
}

This will cause clippy to lint:

warning: redundant closure found
 --> src/main.rs:5:37
  |
5 |     map.entry("bar").or_insert_with(|| vec![]);
  |                                     ^^^^^^^^^ help: remove closure as shown: `$crate::vec::Vec::new`
  |
  = note: `#[warn(clippy::redundant_closure)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure

warning: 1 warning emitted

When using vec![], clippy will suggest $crate::vec::Vec::new which seems a bit complex given that we could just suggest Vec::new (without the path)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions