rust-lang / rust-lang/rust-clippy
`search_is_some` with `matches!` does not work out
Open
@profetia is already working on this.
Since Jan 28, 2026.
I-suggestion-causes-error
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Using the following flags
--force-warn clippy::search-is-some
this code:
fn main() {
let values = [None, Some(3)];
let has_even = values.iter().find(|v| matches!(v, Some(x) if x % 2 == 0)).is_some();
println!("Foo\nbar [BarD] bar\nbaz");
}
caused the following diagnostics:
Checking _16c7f71aabcae39b59ace8eda2bf2cad63d37827 v0.1.0 (/tmp/icemaker_global_tempdir.dESjtcUkYIKG/icemaker_clippyfix_tempdir.WvNPvMHNvUps/_16c7f71aabcae39b59ace8eda2bf2cad63d37827)
warning: called `is_some()` after searching an `Iterator` with `find`
--> src/main.rs:3:34
|
3 | let has_even = values.iter().find(|v| matches!(v, Some(x) if x % 2 == 0)).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| matches!(v, *v if x % 2 == 0))`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#search_is_some
= note: requested on the command line with `--force-warn clippy::search-is-some`
warning: `_16c7f71aabcae39b59ace8eda2bf2cad63d37827` (bin "_16c7f71aabcae39b59ace8eda2bf2cad63d37827") generated 1 warning (run `cargo clippy --fix --bin "_16c7f71aabcae39b59ace8eda2bf2cad63d37827" -p _16c7f71aabcae39b59ace8eda2bf2cad63d37827` to apply 1 suggestion)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.29s
However after applying these diagnostics, the resulting code:
fn main() {
let values = [None, Some(3)];
let has_even = values.iter().any(|v| matches!(v, *v if x % 2 == 0));
println!("Foo\nbar [BarD] bar\nbaz");
}
no longer compiled:
Checking _16c7f71aabcae39b59ace8eda2bf2cad63d37827 v0.1.0 (/tmp/icemaker_global_tempdir.dESjtcUkYIKG/icemaker_clippyfix_tempdir.WvNPvMHNvUps/_16c7f71aabcae39b59ace8eda2bf2cad63d37827)
error: no rules expected `*`
--> src/main.rs:3:54
|
3 | let has_even = values.iter().any(|v| matches!(v, *v if x % 2 == 0));
| ^ no rules expected this token in macro call
|
note: while trying to match meta-variable `$pattern:pat`
--> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/macros/mod.rs:435:24
|
435 | ($expression:expr, $pattern:pat $(if $guard:expr)? $(,)?) => {
| ^^^^^^^^^^^^
error: could not compile `_16c7f71aabcae39b59ace8eda2bf2cad63d37827` (bin "_16c7f71aabcae39b59ace8eda2bf2cad63d37827" test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_16c7f71aabcae39b59ace8eda2bf2cad63d37827` (bin "_16c7f71aabcae39b59ace8eda2bf2cad63d37827") due to 1 previous error
Version:
rustc 1.95.0-nightly (94a0cd15f 2026-01-27)
binary: rustc
commit-hash: 94a0cd15f5976fa35e5e6784e621c04e9f958e57
commit-date: 2026-01-27
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 21.1.8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.