`manual_is_variant_and` ignores the configured MSRV when rewriting `map(...) == Some(...)` comparisons
C-bugI-suggestion-causes-errorI-false-positive
### Summary
The lint `clippy::manual_is_variant_and` does not respect the configured MSRV when it rewrites a `map(...)` versus `Some(...)` comparison. Because the suggested fix is marked safe to apply, `cargo clippy --fix` rewrites the code automatically to call a method that may be too new for the project. The result is code that does not compile.
This only affects the `map(...) == Some(true)` and `map(...) != Some(false)` style comparisons. The other rewrites in the same lint do respect the MSRV. So when a crate sets a lower MSRV, it still gets a fix that breaks the build.
The suggested methods and their minimum Rust versions are:
- `Option::is_some_and` and `Result::is_ok_and`: stable since Rust 1.70.
- `Option::is_none_or`: stable since Rust 1.82.
### Lint Name
`clippy::manual_is_variant_and`
### Reproducer
I tried this code:
```rust
#![warn(clippy::manual_is_variant_and)]
fn main() {
case_is_none_or(None);
case_is_some_and(None);
}
#[clippy::msrv = "1.81"]
fn case_is_none_or(opt: Option<u32>) {
// is_none_or needs Rust 1.82, but the MSRV here is 1.81.
let _ = opt.map(|x| x % 2 == 0) != Some(false);
}
#[clippy::msrv = "1.69"]
fn case_is_some_and(opt: Option<u32>) {
// is_some_and needs Rust 1.70, but the MSRV here is 1.69.
let _ = opt.map(|x| x % 2 == 0) == Some(true);
}
```
I saw this happen:
```
warning: called `.map() != Some()`
--> src/main.rs:11:13
|
11 | let _ = opt.map(|x| x % 2 == 0) != Some(false);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `opt.is_none_or(|x| x % 2 == 0)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_variant_and
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::manual_is_variant_and)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: called `.map() == Some()`
--> src/main.rs:17:13
|
17 | let _ = opt.map(|x| x % 2 == 0) == Some(true);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `opt.is_some_and(|x| x % 2 == 0)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_variant_and
```
I expected to see this happen: clippy should stay quiet for both functions, because each suggested method is newer than the configured MSRV. `is_none_or` is stable since 1.82 but the first function targets 1.81, and `is_some_and` is stable since 1.70 but the second function targets 1.69. The other rewrites in this same lint already stay quiet in that case. The suggestion here is applied automatically by `cargo clippy --fix`, so the code gets rewritten to call a method that does not exist at the configured MSRV and the crate no longer compiles.
The MSRV can also be set in `clippy.toml` with `msrv = "1.81"` instead of using the attribute, with the same result. For `Result`, the same path suggests `is_ok_and`, which has the same minimum version as `is_some_and`, so it breaks the same way under MSRV 1.69.
### Version
```text
clippy 0.1.98 (485ec3fbcc 2026-06-10)
```
### Additional Labels
@rustbot claim
@rustbot label +I-suggestion-causes-error
<!-- TRIAGEBOT_START -->
<!-- TRIAGEBOT_ASSIGN_START -->
<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->
0 条评论