Skip to content

or_fun_call lint shouldn't ignore indexing to HashMap types #6266

Closed
@tesuji

Description

@tesuji

See also the perf improvement in rustc: rust-lang/rust#78508.

Currently, or_fun_call lint doesn't lint on indexing to HashMap types.

I tried this code:

#![warn(clippy::or_fun_call)]
use std::collections::HashMap;
pub fn foo(opt: Option<u32>, map: HashMap<u32, u32>, idx: u32) -> u32 {
    opt.unwrap_or(map[&idx])
}

I expected to see this happen: A warning to unwrap_or method call because
map[&idx] maybe expensive (indexing to a hashmap).

Instead, this happened: No warning at all.

Meta

  • cargo clippy -V: 0.0.212 (2020-10-28 31ee872) from playground
  • rustc -Vv: (2020-10-28 31ee872)

Maybe a duplicate of #5821 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions