Skip to content

or_fun_call bad output with vec![] #1667

Closed
@leonardo-m

Description

@leonardo-m
#![allow(unused_variables)]
fn main() {
    use std::collections::HashMap;
    let mut hash = HashMap::<u32, Vec<u32>>::new();
    let foo = hash.entry(1).or_insert(vec![]);
}

Gives:

warning: use of `or_insert` followed by a function call
 --> src\main.rs:5:15
  |
5 |     let foo = hash.entry(1).or_insert(vec![]);
  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(or_fun_call)] on by default
help: try this
  |     let foo = hash.entry(1).or_insert_with(|| < [ _ ] > :: into_vec ( box [ $ ( $ x ) , * ] ));
  = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#or_fun_call

A nicer looking warning should show .or_insert_with(|| vec![]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions