-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
Summary
The clippy::suboptimal_flops
lint often suggests to use builtin functions such as mul_add()
to make code more performant, but this can lead to errors when using the Complex64
type from the num
crate together with f64
values.
Reproducer
I tried this code:
use num::complex::Complex64;
fn main() {
let a = Complex64::new(1.0, 1.0);
let b = 1.0_f64;
let c = 1.0;
let d = a + b * c;
println!("{d:?}");
}
clippy suggests to rewrite this as:
use num::complex::Complex64;
fn main() {
let a = Complex64::new(1.0, 1.0);
let b = 1.0_f64;
let c = 1.0;
let d = b.mul_add(c, a);
println!("{d:?}");
}
This causes the compiler error:
error[E0308]: mismatched types
--> src/main.rs:8:26
|
8 | let d = b.mul_add(c, a);
| ------- ^ expected `f64`, found `Complex<f64>`
| |
| arguments to this method are incorrect
|
= note: expected type `f64`
found struct `Complex<f64>`
note: method defined here
--> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/f64.rs:270:12
For more information about this error, try `rustc --explain E0308`.
Version
rustc 1.74.0 (79e9716c9 2023-11-13)
binary: rustc
commit-hash: 79e9716c980570bfd1f666e3b16ac583f0168962
commit-date: 2023-11-13
host: x86_64-unknown-linux-gnu
release: 1.74.0
LLVM version: 17.0.4
Additional Labels
I-suggestion-causes-error
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing