Skip to content

fix: Improve floating point lint to handle ambiguous type #15133

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

Merged
merged 3 commits into from
Jul 6, 2025

Conversation

odysa
Copy link
Contributor

@odysa odysa commented Jun 25, 2025

Fixes: #14897, #10015

This is not a perfect solution, but it fixes the issue. Happy to discuss further with the clippy team.

This PR refines check_mul_add to avoid false positives on ambiguous float types (e.g., f32 vs f64). It improves type detection and ensures mul_add is only suggested when the type is clear.

Changes:

  • Improved detection of ambiguous float types
  • Refined mul_add suggestion logic
  • Added tests for ambiguous cases

Example

Before this change, expressions like:

let x = 1.0; // ambiguous type
let _ = x * 2.0 + 0.5; // could incorrectly suggest mul_add

changelog: [suboptimal_flops]: improve handling of ambiguous float types in mul_add suggestions

@odysa odysa changed the title fix mul_add broken sugg fix: Improve floating point arithmetic lint to handle ambiguous type Jun 26, 2025
@odysa odysa changed the title fix: Improve floating point arithmetic lint to handle ambiguous type fix: Improve floating point lint to handle ambiguous type Jun 26, 2025
@odysa odysa marked this pull request as ready for review June 26, 2025 00:49
@rustbot
Copy link
Collaborator

rustbot commented Jun 26, 2025

r? @llogiq

rustbot has assigned @llogiq.
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 Jun 26, 2025
@llogiq
Copy link
Contributor

llogiq commented Jul 6, 2025

I agree that a suboptimal solution is better than no solution.

@llogiq llogiq added this pull request to the merge queue Jul 6, 2025
@llogiq
Copy link
Contributor

llogiq commented Jul 6, 2025

Thanks, and we can do a followup PR if we happen upon a better solution.

Merged via the queue into rust-lang:master with commit 412def2 Jul 6, 2025
23 of 27 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo clippy --fix tries to apply mul_add but causes [E0689]
3 participants