Open
Description
Summary
if i do a map_or(false
in an assert!, it suggests i should use a == Some(
, but it adds unnecessary parentheses around the expression.
Reproducer
I tried this code:
fn main() {
let output = Some("test");
assert!(output.map_or(false, |x| x == "test"));
}
I expected to see this happen:
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)
Instead, this happened:
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)
(note the extra parentheses in assert!((output == Some("test")));
)
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
Additional Labels
No response