rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

`or_fun_call` doesn't suggest `map_or_else`

Open junbl opened this issue 3 years ago • 1 comments

Summary

When calling map_or with a function call as the default value, clippy does not suggest writing it with map_or_else instead as it does for the other or methods.

This may be related to #5821.

Lint Name

or_fun_call

Reproducer

#![deny(clippy::or_fun_call)]

fn g() -> i32 { 3 }

fn main() {
    let v = Some(4);
    
    v.map_or(g(), |v| v);
    v.map_or_else(g, |v| v);
}

Playground link

I expected to see this happen:

The line with map_or should trigger the lint, suggesting the code below it.

Instead, this happened:

No lint is produced.

Version

rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-unknown-linux-gnu
release: 1.61.0
LLVM version: 14.0.0

junbl avatar Jun 13 '22 15:06 junbl

@rustbot claim

alex-semenyuk avatar Jul 11 '22 16:07 alex-semenyuk

@rustbot claim

koka831 avatar Oct 22 '22 07:10 koka831