Skip to content

lints: constant_bool_expr: detect constant booleans expressions using && or ||#17417

Open
poliorcetics wants to merge 2 commits into
rust-lang:masterfrom
poliorcetics:ab/lints-constant-bool-expr-add-support-for-rudimentary-const-eval/lukkmqzkzmuq
Open

lints: constant_bool_expr: detect constant booleans expressions using && or ||#17417
poliorcetics wants to merge 2 commits into
rust-lang:masterfrom
poliorcetics:ab/lints-constant-bool-expr-add-support-for-rudimentary-const-eval/lukkmqzkzmuq

Conversation

@poliorcetics

@poliorcetics poliorcetics commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Detects expressions of the form a != b || a != c or a == b && a == c (where a, b, and c are all unique expressions) to warn about them: they evaluate either always to true or always to false, which is very likely a logic bug.

Closes #853

changelog: [constant_bool_expr]: detect constant booleans expressions using && or ||

@rustbot rustbot added the S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. label Jul 13, 2026
@rustbot

rustbot commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome!

You should hear from one of our reviewers after this PR gets at least 2 reviews from the community.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jul 13, 2026
@poliorcetics poliorcetics force-pushed the ab/lints-constant-bool-expr-add-support-for-rudimentary-const-eval/lukkmqzkzmuq branch from 93b4f6c to 4e3aa57 Compare July 13, 2026 16:22
@rustbot

rustbot commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@DanielEScherzer DanielEScherzer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

community review: not going to pretend like I fully understand this, but found a minor simplification, see inline

View changes since this review

Comment thread clippy_lints/src/operators/constant_bool_expr.rs Outdated
Comment thread clippy_lints/src/operators/constant_bool_expr.rs Outdated
… `&&` or `||`

For now this only detects simple cases using literals.
@poliorcetics poliorcetics force-pushed the ab/lints-constant-bool-expr-add-support-for-rudimentary-const-eval/lukkmqzkzmuq branch from 4e3aa57 to 7a35b90 Compare July 14, 2026 07:48
@poliorcetics poliorcetics force-pushed the ab/lints-constant-bool-expr-add-support-for-rudimentary-const-eval/lukkmqzkzmuq branch from 7a35b90 to 77a7856 Compare July 14, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lint x != _ || x != _

3 participants