Skip to content

or_fn_call lint suggests broken code #5693

Closed
@DevinR528

Description

@DevinR528

While working on a lint I got this warning in the dog food tests

error: use of `or_insert` followed by a function call
   --> clippy_lints/src/macro_use.rs:185:34
    |
185 | ...                   .or_insert(vec![])
    |                        ^^^^^^^^^^^^^^^^^ help: try this: `or_insert_with(vec![])`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call

The suggestions also fails to compile vec![] is not a function error. So fixing that with or_insert_with(|| vec![]) gives

error: redundant closure found
   --> clippy_lints/src/macro_use.rs:194:49
    |
194 | ...                   .or_insert_with(|| vec![])
    |                                       ^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure

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