Skip to content

const functions should not trigger or_fun_call  #6943

@Sciencentistguy

Description

@Sciencentistguy

Lint name: or_fun_call

I tried this code:

let x = None;
let s: &str = "hello world";
s.unwrap_or(s.len());

I expected to see this happen: As str::len is a const function, it is inlined as a usize. So the suggestion to use .unwrap_or_else() introduces more overhead than is needed.

Instead, this happened: The lint is triggered

Meta

  • cargo clippy -V: clippy 0.1.52 (f5d8117 2021-03-16)
  • rustc -Vv:
rustc 1.52.0-nightly (f5d8117c3 2021-03-16)
binary: rustc
commit-hash: f5d8117c338a788bd24abec733fd143dfceb25a0
commit-date: 2021-03-16
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 12.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't havegood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions