Skip to content
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

Extend implicit_saturating_sub lint #12476

Merged
merged 6 commits into from
Aug 31, 2024

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Mar 13, 2024

Fixes #10070.

It can serve as base if we want to add equivalent checks for other arithmetic operations.

Also one important note: when writing this lint, I realized that I could check for wrong conditions performed beforehand on subtraction and added another part in the lint. Considering they both rely on the same checks, I kept both in the same place. Not sure if it makes sense though...

changelog: Extend implicit_saturating_sub lint

@rustbot
Copy link
Collaborator

rustbot commented Mar 13, 2024

r? @Manishearth

rustbot has assigned @Manishearth.
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 Mar 13, 2024
@Manishearth
Copy link
Member

r? clippy

still busy

@rustbot rustbot assigned flip1995 and unassigned Manishearth Mar 13, 2024
@bors
Copy link
Collaborator

bors commented Mar 17, 2024

☔ The latest upstream changes (presumably #12451) made this pull request unmergeable. Please resolve the merge conflicts.

@GuillaumeGomez
Copy link
Member Author

Fixed merge conflict.

r? @y21

@rustbot rustbot assigned y21 and unassigned flip1995 Mar 17, 2024
Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

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

Neat lint idea, but I'm not too sure what we want to do with the other implicit_saturating_{sub,add}/manual_saturating_arithmetic lints since they all seem really similar in their name and what they're intending to catch.
With this, we'd have four different lints that all look for manual (saturating) arithmetic

clippy_lints/src/manual_arithmetic_check.rs Outdated Show resolved Hide resolved
clippy_lints/src/manual_arithmetic_check.rs Outdated Show resolved Hide resolved
clippy_lints/src/manual_arithmetic_check.rs Outdated Show resolved Hide resolved
clippy_lints/src/manual_arithmetic_check.rs Outdated Show resolved Hide resolved
clippy_lints/src/manual_arithmetic_check.rs Outdated Show resolved Hide resolved
clippy_lints/src/manual_arithmetic_check.rs Outdated Show resolved Hide resolved
tests/ui/manual_arithmetic_check.rs Show resolved Hide resolved
clippy_lints/src/manual_arithmetic_check.rs Outdated Show resolved Hide resolved
@GuillaumeGomez GuillaumeGomez changed the title Add new manual_arithmetic_check lint Extend implicit_saturating_sub lint Mar 19, 2024
@GuillaumeGomez
Copy link
Member Author

@y21: Instead of creating a new lint, I extended implicit_saturating_sub instead.

@y21
Copy link
Member

y21 commented Mar 27, 2024

I haven't forgotten about this, will try to look at it again soon :)

@xFrednet
Copy link
Member

Hey, this is a ping from triage. @y21 can you give this PR a review? It's totally fine if you don't have the time right now, you can reassign the PR to a random team member using r? clippy.

@rustbot ready

Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

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

Sorry, I completely forgot about this 😅 thanks for reminding me

clippy_lints/src/implicit_saturating_sub.rs Outdated Show resolved Hide resolved
tests/ui/manual_arithmetic_check.rs Show resolved Hide resolved
clippy_lints/src/implicit_saturating_sub.rs Outdated Show resolved Hide resolved
tests/ui/manual_arithmetic_check-2.stderr Outdated Show resolved Hide resolved
tests/ui/manual_arithmetic_check-2.stderr Outdated Show resolved Hide resolved
@GuillaumeGomez GuillaumeGomez force-pushed the add-manual_arithmetic_check branch 3 times, most recently from 6acaf81 to 91ebe40 Compare June 28, 2024 13:55
@GuillaumeGomez
Copy link
Member Author

Changes I pushed:

  • Added test with other statement in if/else to ensure it doesn't lint.
  • Added test with floats to ensure it doesn't lint.
  • Added test for new checks for <= and >=.
  • Updated code to limit the use of peel_blocks.
  • Added #[allow(...)] to ignore non-related lints.

With this I think I covered all cases. Thanks a lot @y21!

@GuillaumeGomez
Copy link
Member Author

Fixed the test I added. Sorry for the delay.

@GuillaumeGomez
Copy link
Member Author

Updated!

@GuillaumeGomez
Copy link
Member Author

Added MSRV check in const context.

@GuillaumeGomez
Copy link
Member Author

Fixed dogfood!

Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

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

Some small nits for the last change. I'll start the FCP in the meantime since this shouldn't really be a blocker for that I don't think

clippy_lints/src/implicit_saturating_sub.rs Outdated Show resolved Hide resolved
clippy_lints/src/implicit_saturating_sub.rs Outdated Show resolved Hide resolved
@GuillaumeGomez
Copy link
Member Author

Applied suggestions.

@y21 y21 added S-final-comment-period Status: final comment period it will be merged unless new objections are raised (~1 week) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Aug 22, 2024
@GuillaumeGomez
Copy link
Member Author

Rebased on master and fixed dogfood.

Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

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

Looks all good to me now! Thanks for bearing with me for so long 😄

The FCP for the new lint has been open for a while but didn't get any comments (meaning no concerns), so I think we can just consider it complete now.

Mind squashing some of the commits? Specifically commits like dogfood etc. You can r=me with that

@GuillaumeGomez
Copy link
Member Author

Done. Time for r+. :D

@bors r=y21

@bors
Copy link
Collaborator

bors commented Aug 31, 2024

@GuillaumeGomez: 🔑 Insufficient privileges: Not in reviewers

@GuillaumeGomez
Copy link
Member Author

Ah apparently not. ^^'

@Jarcho
Copy link
Contributor

Jarcho commented Aug 31, 2024

@bors r=y21

@bors
Copy link
Collaborator

bors commented Aug 31, 2024

📌 Commit 2832faf has been approved by y21

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Aug 31, 2024

⌛ Testing commit 2832faf with merge ac914d3...

@bors
Copy link
Collaborator

bors commented Aug 31, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: y21
Pushing ac914d3 to master...

@bors bors merged commit ac914d3 into rust-lang:master Aug 31, 2024
11 checks passed
@GuillaumeGomez GuillaumeGomez deleted the add-manual_arithmetic_check branch August 31, 2024 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-final-comment-period Status: final comment period it will be merged unless new objections are raised (~1 week)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

extension to manual_saturating_arithmetic
8 participants