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

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

Conversation

odysa
Copy link

@odysa odysa commented Jun 25, 2025

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

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

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

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