Skip to content

feat(lints): add unsigned_subtraction_gt_zero lint for comparisons against zero after subtraction - #15820

Open
AMS21 wants to merge 1 commit into
rust-lang:masterfrom
AMS21:unsigned_subtraction_gt_zero
Open

feat(lints): add unsigned_subtraction_gt_zero lint for comparisons against zero after subtraction#15820
AMS21 wants to merge 1 commit into
rust-lang:masterfrom
AMS21:unsigned_subtraction_gt_zero

Conversation

@AMS21

@AMS21 AMS21 commented Oct 6, 2025

Copy link
Copy Markdown

changelog: new lint: [unsigned_subtraction_gt_zero] Lints comparisons of an unsigned integer subtraction against zero, like (a - b) > 0.

If a < b, a - b will panic in debug builds and wrap in release builds, making the effectively behave like a != b. This is likely unintended; a > b is clearer and avoids potential panics and wraparound.

Fixes #588

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 6, 2025
@rustbot

rustbot commented Oct 6, 2025

Copy link
Copy Markdown
Collaborator

r? @Alexendoo

rustbot has assigned @Alexendoo.
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

@github-actions

github-actions Bot commented Oct 6, 2025

Copy link
Copy Markdown

Lintcheck changes for e452f1b

Lint Added Removed Changed
clippy::unsigned_subtraction_gt_zero 1 0 0

This comment will be updated if you push new changes

@AMS21
AMS21 force-pushed the unsigned_subtraction_gt_zero branch 3 times, most recently from 8efc16d to 5effb08 Compare October 7, 2025 08:29
@samueltardieu samueltardieu added the needs-fcp PRs that add, remove, or rename lints and need an FCP label Oct 17, 2025
@rustbot

This comment has been minimized.

@AMS21
AMS21 force-pushed the unsigned_subtraction_gt_zero branch from 5effb08 to 0949f6e Compare October 20, 2025 10:09
@rustbot

This comment has been minimized.

Comment thread clippy_lints/src/operators/unsigned_subtraction_gt_zero.rs Outdated
@Alexendoo Alexendoo added S-final-comment-period Status: final comment period it will be merged unless new objections are raised (~1 week) and removed needs-fcp PRs that add, remove, or rename lints and need an FCP labels Oct 20, 2025
@Alexendoo

Copy link
Copy Markdown
Member

Opened https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/FCP.20unsigned_subtraction_gt_zero/with/546064561

@AMS21
AMS21 force-pushed the unsigned_subtraction_gt_zero branch from 0949f6e to ed98d29 Compare October 20, 2025 19:02
@rustbot rustbot added the needs-fcp PRs that add, remove, or rename lints and need an FCP label Oct 20, 2025
@AMS21
AMS21 force-pushed the unsigned_subtraction_gt_zero branch from ed98d29 to 843f706 Compare October 20, 2025 19:43
@rustbot

This comment has been minimized.

@AMS21
AMS21 force-pushed the unsigned_subtraction_gt_zero branch from 843f706 to f0b2dae Compare October 30, 2025 09:38
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@AMS21
AMS21 force-pushed the unsigned_subtraction_gt_zero branch from f0b2dae to 12df45f Compare November 30, 2025 10:07
@rustbot

This comment has been minimized.

@AMS21
AMS21 force-pushed the unsigned_subtraction_gt_zero branch 2 times, most recently from a395cb2 to fee9179 Compare November 30, 2025 10:15
Comment thread clippy_lints/src/operators/unsigned_subtraction_gt_zero.rs Outdated
Comment thread clippy_lints/src/operators/unsigned_subtraction_gt_zero.rs Outdated
Comment thread clippy_lints/src/operators/unsigned_subtraction_gt_zero.rs Outdated
Comment thread clippy_lints/src/operators/mod.rs Outdated
@AMS21
AMS21 force-pushed the unsigned_subtraction_gt_zero branch from fee9179 to 6716fb2 Compare March 2, 2026 14:29
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@AMS21
AMS21 force-pushed the unsigned_subtraction_gt_zero branch from 6716fb2 to 6b87db2 Compare March 5, 2026 16:56
@rustbot

rustbot commented Mar 5, 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.

@AMS21
AMS21 force-pushed the unsigned_subtraction_gt_zero branch from 6b87db2 to e452f1b Compare March 5, 2026 17:37
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-final-comment-period Status: final comment period it will be merged unless new objections are raised (~1 week) 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 unsigned - other_unsigned > 0

4 participants