Skip to content

manual_is_variant_and should also trigger for some_option.map(|x| x.is_foo) == Some(true) #14542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sdroege opened this issue Apr 4, 2025 · 1 comment · Fixed by #14646
Closed
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@sdroege
Copy link

sdroege commented Apr 4, 2025

Summary

See title :)

Lint Name

manual_is_variant_and

Reproducer

I tried this code:

let x = Some(2).map(|x| x % 2 == 0) == Some(true);

I expected to see this happen:

Suggestion to use let x = Some(2).is_some_and(|x| x % 2 == 0);

Instead, this happened:

Nothing

Version

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7
@sdroege sdroege added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Apr 4, 2025
@GuillaumeGomez
Copy link
Member

Any equality comparison expression where an arm ends with a map call returning a bool should be using is_some_and. Gonna take a look in the next days.

github-merge-queue bot pushed a commit that referenced this issue May 2, 2025
I'm working on #14542 and
I decided to name the lint `unnecessary_map` originally. However when I
ran the command, I got:

```
thread 'main' panicked at clippy_dev/src/new_lint.rs:450:5:
Lint `unnecessary_map` already defined in `/home/imperio/rust/clippy/clippy_lints/src/methods/mod.rs`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

It's because there is already a `unnecessary_map_or`, which matches the
`.contains()` call. This PR strengthens this check.

changelog: Fix `new_lint` clippy command

r? @flip1995
github-merge-queue bot pushed a commit that referenced this issue May 28, 2025
…ons (#14646)

Fixes #14542.

changelog: [`manual_is_variant_and`]: Extend to check for boolean map
comparisons

r? @samueltardieu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants