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

float_cmp changes #11948

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

float_cmp changes #11948

wants to merge 10 commits into from

Conversation

Jarcho
Copy link
Contributor

@Jarcho Jarcho commented Dec 10, 2023

fixes #2834
fixes #6816


changelog: This:

  • Deprecated float_cmp_const in favor of a config option on [float_cmp].
    #11948
  • [float_cmp] #11948
    • Add the [float-cmp-ignore-named-constants] configuration to ignore comparisons to named constants.
    • Add the [float-cmp-ignore-change-detection] configuration to ignore const-evaluatabled values.
    • Add the [float-cmp-ignore-constant-comparisons] configuration to ignore comparisons to the modification of an operand (e.g. x == f(x)).

@rustbot
Copy link
Collaborator

rustbot commented Dec 10, 2023

r? @giraffate

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 10, 2023
@bors
Copy link
Collaborator

bors commented Dec 29, 2023

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

@Jarcho
Copy link
Contributor Author

Jarcho commented Feb 14, 2024

r? clippy

@bors
Copy link
Collaborator

bors commented Feb 19, 2024

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

@xFrednet
Copy link
Member

xFrednet commented Apr 1, 2024

Hey @Jarcho woudl you mind rebasing this PR?

Hey @GuillaumeGomez, if you have the time, could you give this PR a review?

r? xFrednet

@rustbot rustbot assigned xFrednet and unassigned matthiaskrgr Apr 1, 2024
@Jarcho Jarcho force-pushed the float_cmp branch 2 times, most recently from f768816 to b6623ac Compare June 7, 2024 21:47
@bors
Copy link
Collaborator

bors commented Jun 27, 2024

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

Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

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

You have a good structure as usual! I've reviewed the implementation and left some comments. Mostly optional nits and some questions. I've started on the tests but haven't checked all of them yet.

clippy_lints/src/operators/float_cmp.rs Show resolved Hide resolved
clippy_lints/src/operators/float_cmp.rs Show resolved Hide resolved
clippy_lints/src/operators/float_cmp.rs Show resolved Hide resolved
clippy_lints/src/operators/float_cmp.rs Show resolved Hide resolved
tests/ui-toml/float_cmp_change_detection/test.rs Outdated Show resolved Hide resolved
clippy_config/src/conf.rs Outdated Show resolved Hide resolved
Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

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

The current version looks good to me. I want to wait for a response from @blyxyas, but I don't expect there to be a noticeable impact based on your implementation.

@xFrednet
Copy link
Member

Roses == Red
Violets == Blue
(Floats - Color).abs() < Something
This is not a poem

@bors
Copy link
Collaborator

bors commented Jul 16, 2024

📌 Commit c3c15d0 has been approved by xFrednet

It is now in the queue for this repository.

bors added a commit that referenced this pull request Jul 16, 2024
`float_cmp` changes

fixes #2834
fixes #6816

---

changelog: This:
* Deprecated `float_cmp_const` in favor of a config option on [`float_cmp`].
  [#11948](#11948)
* [`float_cmp`]: Don't lint literal and self comparisons.
  [#11948](#11948)
* [`float_cmp`] [#11948](#11948)
    * Add the [`float-cmp-ignore-named-constants`] configuration to ignore comparisons to named constants.
    * Add the [`float-cmp-ignore-change-detection`] configuration to ignore const-evaluatabled values.
    * Add the [`float-cmp-ignore-constant-comparisons`] configuration to ignore comparisons to the modification of an operand (e.g. `x == f(x)`).
@bors
Copy link
Collaborator

bors commented Jul 16, 2024

⌛ Testing commit c3c15d0 with merge 3a97f5a...

@bors
Copy link
Collaborator

bors commented Jul 16, 2024

💔 Test failed - checks-action_test

@bors
Copy link
Collaborator

bors commented Jul 17, 2024

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

@Jarcho Jarcho force-pushed the float_cmp branch 2 times, most recently from e1550af to 083300b Compare July 18, 2024 17:54
@Jarcho
Copy link
Contributor Author

Jarcho commented Jul 18, 2024

Latest commit changes named constants to be allowed individually rather than as a group. This feature was originally added to allow comparisons to a sentinel value rather than constants in general.

Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

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

One comment and then I'd say it's good to go :D

/// x == VALUE
/// }
/// ```
(float_cmp_allowed_constants: Vec<String> = Vec::new()),
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest adding "*" as a magic value that says that all constants are allowed. THis should also be documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would be better done in a more uniform way across all the multi-value configs.

Copy link
Member

Choose a reason for hiding this comment

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

While true, I'm not sure how many lints would benefit from an everything "*" configuration. #12571 comes to mind, where I also suggested this with a Zulip thread.

@Jarcho
Copy link
Contributor Author

Jarcho commented Jul 19, 2024

An alternative to the current configs would be to have a single heuristics config taking a list of names. e.g.

float_cmp_heuristics = ["constant_cmp", "change_detection", "signum_cmp", "cmp_zero"]

This would make it possible to preemptively disable future heuristics as well as an easier way to disable all of them.

@xFrednet
Copy link
Member

This would make it possible to preemptively disable future heuristics as well as an easier way to disable all of them.

Having heuristics as strings in a list feels weird to me. They should be boolean flags IMO. That also makes it easier for format error reporting etc

@bors
Copy link
Collaborator

bors commented Jul 27, 2024

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

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
8 participants