Skip to content

manual_mul_add suggests broken code #4726

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
matthiaskrgr opened this issue Oct 24, 2019 · 3 comments · Fixed by #4897
Closed

manual_mul_add suggests broken code #4726

matthiaskrgr opened this issue Oct 24, 2019 · 3 comments · Fixed by #4897
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@matthiaskrgr
Copy link
Member

let x = f64::from(32) + 2.0 * 4.0;

clippy suggests

warning: consider using mul_add() for better numerical precision
 --> src/main.rs:3:10
  |
3 |     let x = f64::from(32) + 2.0 * 4.0;
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `2.0.mul_add(4.0, f64::from(32))`
  |

but

	 let x = 2.0.mul_add(4.0, f64::from(32));

does not compile:

error[E0599]: no method named `mul_add` found for type `{float}` in the current scope
 --> src/main.rs:4:15
  |
4 |      let x = 2.0.mul_add(4.0, f64::from(32));
  |                  ^^^^^^^ method not found in `{float}`

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Oct 24, 2019
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Oct 24, 2019

This compiles:

	let x = 2.0_f64.mul_add(4.0, f64::from(32));

Perhaps we just need the additional type annotation?

@matthiaskrgr
Copy link
Member Author

If my code is f64::from(32) + 2. * 4.;, clippy suggests 2..mul_add(4., f64::from(32)), the 2..mul_add( also looks kinda questionable imo.

@flip1995
Copy link
Member

cc #4602 (comment)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants