rust-lang / rust-lang/rust-clippy

suggest `== Some(` for `is_some_and` if possible

Open
#14,713 2 comments 1 reaction 1 assignee View on GitHub

@alex-semenyuk is already working on this.

Since Apr 30, 2025.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.