-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
Summary
the unnecessary_map_or lint usually suggests using an is_some_and in favor of a map_or(false, but if it is possible it sugests an == Some( instead. but if i write the is_some_and initially, then clippy will not suggest me to change it to == Some(, even if it is possible.
Lint Name
unnecessary_map_or
Reproducer
I tried this code:
fn main() {
let output = Some("test");
assert!(output.is_some_and(|x| x == "test"));
}I expected to see this happen:
warning: this `is_some_and` can be simplified
--> src/main.rs:3:10
|
3 | assert!(output.is_some_and(|x| x == "test"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or
= note: `#[warn(clippy::unnecessary_map_or)]` on by default
help: use a standard comparison instead
|
3 - assert!(output.is_some_and(|x| x == "test"));
3 + assert!((output == Some("test")));
|
warning: `stuff` (bin "stuff") generated 1 warning (run `cargo clippy --fix --bin "stuff"` to apply 1 suggestion)
Instead, this happened:
nothing.
if i instead do this:
fn main() {
let output = Some("test");
assert!(output.map_or(false, |x| x == "test"));
}i get the output i want:
warning: this `map_or` can be simplified
--> src/main.rs:3:10
|
3 | assert!(output.map_or(false, |x| x == "test"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or
= note: `#[warn(clippy::unnecessary_map_or)]` on by default
help: use a standard comparison instead
|
3 - assert!(output.map_or(false, |x| x == "test"));
3 + assert!((output == Some("test")));
|
warning: `stuff` (bin "stuff") generated 1 warning (run `cargo clippy --fix --bin "stuff"` to apply 1 suggestion)
Version
rustc 1.88.0-nightly (cb31a009e 2025-04-27)
binary: rustc
commit-hash: cb31a009e3e735ab08613cec2d8a5a754e65596f
commit-date: 2025-04-27
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2
edwloef
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't