Skip to content

float_cmp changes - #11948

Open
Jarcho wants to merge 10 commits into
rust-lang:masterfrom
Jarcho:float_cmp
Open

float_cmp changes#11948
Jarcho wants to merge 10 commits into
rust-lang:masterfrom
Jarcho:float_cmp

Conversation

@Jarcho

@Jarcho Jarcho commented Dec 10, 2023

Copy link
Copy Markdown
Contributor

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

rustbot commented Dec 10, 2023

Copy link
Copy Markdown
Collaborator

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

bors commented Dec 29, 2023

Copy link
Copy Markdown
Contributor

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

@Jarcho
Jarcho force-pushed the float_cmp branch 4 times, most recently from 147961e to e0a1fc6 Compare February 14, 2024 00:24
@Jarcho

Jarcho commented Feb 14, 2024

Copy link
Copy Markdown
Contributor Author

r? clippy

@bors

bors commented Feb 19, 2024

Copy link
Copy Markdown
Contributor

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

@xFrednet

xFrednet commented Apr 1, 2024

Copy link
Copy Markdown
Contributor

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
Comment thread clippy_lints/src/operators/float_cmp.rs
Comment thread clippy_lints/src/operators/float_cmp.rs
Comment thread tests/ui-toml/float_cmp_named_constants/test.rs Outdated
Comment thread clippy_lints/src/operators/float_cmp.rs Outdated
Comment thread tests/ui-toml/float_cmp_constant_comparisons/test.rs Outdated
Comment thread clippy_lints/src/operators/float_cmp.rs Outdated
Comment thread clippy_lints/src/operators/float_cmp.rs
Comment thread tests/ui-toml/float_cmp_change_detection/test.rs Outdated
Comment thread clippy_lints/src/operators/float_cmp.rs
@Jarcho
Jarcho force-pushed the float_cmp branch 2 times, most recently from f768816 to b6623ac Compare June 7, 2024 21:47
@bors

bors commented Jun 27, 2024

Copy link
Copy Markdown
Contributor

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

@xFrednet

Copy link
Copy Markdown
Contributor

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

@bors

bors commented Jul 16, 2024

Copy link
Copy Markdown
Contributor

📌 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

bors commented Jul 16, 2024

Copy link
Copy Markdown
Contributor

⌛ Testing commit c3c15d0 with merge 3a97f5a...

@bors

bors commented Jul 16, 2024

Copy link
Copy Markdown
Contributor

💔 Test failed - checks-action_test

@bors

bors commented Jul 17, 2024

Copy link
Copy Markdown
Contributor

☔ 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

Jarcho commented Jul 18, 2024

Copy link
Copy Markdown
Contributor Author

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.

@xFrednet xFrednet 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.

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

Comment thread clippy_config/src/conf.rs
/// x == VALUE
/// }
/// ```
(float_cmp_allowed_constants: Vec<String> = Vec::new()),

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.

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

Jarcho commented Jul 19, 2024

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Contributor

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

bors commented Jul 27, 2024

Copy link
Copy Markdown
Contributor

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

@xFrednet xFrednet added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Oct 26, 2024
@xFrednet

Copy link
Copy Markdown
Contributor

I'm unassigning myself from this PR. @Jarcho if you want to continue this work, please request a new reviewer with r? clippy

@xFrednet xFrednet removed their assignment Mar 16, 2025
@rustbot

rustbot commented Mar 31, 2025

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly d28d234) 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-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

float_cmp false positive: catching underflow EPSILON is a bad error margin and should not be recommended [float_cmp]

8 participants