Skip to content

Conversation

ada4a
Copy link
Contributor

@ada4a ada4a commented Aug 15, 2025

The issue that this PR was opened to fix (#15367), talked about how, for !x == false, this lint suggests both:

  1. x != false
  2. x

I initially wanted to make the lint short-circuit after emitting the first suggestion (since that was the easier change code-wise), but that was not optimal for two reasons:

  1. suggestion 2 is obviously better (the other one requires one more round of Clippy)
  2. suggestion 1 is actually already covered by nonminimal_bool

And so I instead decided to completely remove the code path that emits suggestion 1.

Fixes #15367

changelog: [bool_comparison]: no longer lint on !x != y

@rustbot
Copy link
Collaborator

rustbot commented Aug 15, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 15, 2025
Copy link
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r? samueltardieu
@rustbot blocked
(by #15513)

I haven't checked if non-bool to bool comparaison is handled, I'll do this when reviewing once #15513 is merged.

@rustbot rustbot assigned samueltardieu and unassigned Jarcho Aug 22, 2025
@rustbot rustbot added S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Aug 22, 2025
@ada4a ada4a force-pushed the bool-comparison branch 2 times, most recently from 0664c16 to ea79f2a Compare August 22, 2025 18:13
@rustbot

This comment has been minimized.

@ada4a
Copy link
Contributor Author

ada4a commented Aug 22, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work labels Aug 22, 2025
@ada4a ada4a force-pushed the bool-comparison branch 3 times, most recently from 9d47638 to 194aa0b Compare August 22, 2025 20:24
misc: rm "as shown" from help message - clippy guidelines recommend against this

misc: pull conditions into let-chain

misc: use `Span::to`

misc: inline `{l,r}_ty`

misc: move the type checks out of `check_comparison`

misc: make test cases much less verbose
@samueltardieu samueltardieu added this pull request to the merge queue Aug 22, 2025
Merged via the queue into rust-lang:master with commit 3a3d3e4 Aug 22, 2025
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 22, 2025
@ada4a ada4a deleted the bool-comparison branch August 22, 2025 21:49
github-merge-queue bot pushed a commit that referenced this pull request Aug 23, 2025
For some reason I don't really understand, this lint was mushed together
with `needless_bool(_assign)`, even though they seemingly didn't have a
lot of overlapping logic -- for one, their lint passes are separate, and
can't be merged in a meaningful way.

I first wanted to move the file under `booleans/` and move the common
logic into `utils.rs`, and then split the files, but it turns out that
the entirety of common logic was the `fetch_bool_expr` function, which
is literally just `expr.as_literal()?.as_bool()`. So I scratched that
idea, moved `bool_comparison` logic to a new file, and copy-pasted the
function into it.

I think this change is advantageous in two main ways:
1. no confusing intermingling of two different passes' logics
2. the file that defines `clippy::bool_comparison` becomes easier to
find, because now there's a file with that name.

This PR depends on #15498,
but only for easier-rebase purposes.

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bool_comparison triggers twice on the same code
4 participants