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

Add new lint while_float #12765

Merged
merged 2 commits into from May 21, 2024
Merged

Add new lint while_float #12765

merged 2 commits into from May 21, 2024

Conversation

yusufraji
Copy link
Contributor

This PR adds a nursery lint that checks for while loops comparing floating point values.

changelog:

changelog: [`while_float`]: Checks for while loops comparing floating point values.

Fixes #758

@rustbot
Copy link
Collaborator

rustbot commented May 5, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @xFrednet (or someone else) some time within the next two weeks.

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 the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 5, 2024
@yusufraji yusufraji changed the title Add new lint `whle Add new lint while_float May 5, 2024
@yusufraji
Copy link
Contributor Author

r? @llogiq

@rustbot rustbot assigned llogiq and unassigned xFrednet May 5, 2024
@llogiq
Copy link
Contributor

llogiq commented May 11, 2024

Thank you for making clippy better! This is a good starting point. We might want to extend the lint to look into the loop variant and check if the increment is integer, but as this is a nursery lint, we might well do that in a follow-up PR.

So I just left a small doc suggestion, otherwise this looks good to merge.

Co-authored-by: llogiq <bogusandre@gmail.com>
@llogiq
Copy link
Contributor

llogiq commented May 21, 2024

Ok, let's merge this and see how it fares.

@bors r+

If you'd like to keep working on this lint, here are some ideas for possible future directions:

  1. Try to extract a constant from the comparison arguments and check if it is integral. If not, avoid linting.
  2. Try to extract the loop variable and walk the loop body to find the increment(s), then also check that those are integral.
  3. (once 2. is in place), visit the whole method looking for uses of that variable and check if all can be converted to integer math. If so, add a multi-suggestion changing all found uses. Note: This is pretty advanced stuff already.

@bors
Copy link
Collaborator

bors commented May 21, 2024

📌 Commit cb3fcbb has been approved by llogiq

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented May 21, 2024

⌛ Testing commit cb3fcbb with merge 2efebd2...

@bors
Copy link
Collaborator

bors commented May 21, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing 2efebd2 to master...

@bors bors merged commit 2efebd2 into rust-lang:master May 21, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 float loops
5 participants