diff options
| author | Lukas Lueg <lukas.lueg@gmail.com> | 2023-11-18 13:50:18 +0100 |
|---|---|---|
| committer | Lukas Lueg <lukas.lueg@gmail.com> | 2023-11-18 13:50:18 +0100 |
| commit | a2e396badfb1e36ba885480da4f7994fec1e2deb (patch) | |
| tree | 83113e3984c9acf8c7bac2ddc7f0a3377fa03ae0 /tests | |
| parent | e8e95102191dc0e2b718c8030103cfafd0869bf5 (diff) | |
| download | rust-a2e396badfb1e36ba885480da4f7994fec1e2deb.tar.gz rust-a2e396badfb1e36ba885480da4f7994fec1e2deb.zip | |
Don't suggest `a.mul_add(b, c)` if parameters are not float
clippy::suboptimal_flops used to not check if the second parameter to f32/f64.mul_add() was float. Since the method is only defined to take `Self` as paremters, the suggestion was wrong. Fixes #11831
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/floating_point_mul_add.fixed | 18 | ||||
| -rw-r--r-- | tests/ui/floating_point_mul_add.rs | 18 |
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/ui/floating_point_mul_add.fixed b/tests/ui/floating_point_mul_add.fixed index a4d6d49e57c..3ce2edf2c71 100644 --- a/tests/ui/floating_point_mul_add.fixed +++ b/tests/ui/floating_point_mul_add.fixed @@ -39,3 +39,21 @@ fn main() { // Cases where the lint shouldn't be applied let _ = (a * a + b * b).sqrt(); } + +fn _issue11831() { + struct NotAFloat; + + impl std::ops::Add<f64> for NotAFloat { + type Output = Self; + + fn add(self, _: f64) -> Self { + NotAFloat + } + } + + let a = NotAFloat; + let b = 1.0_f64; + let c = 1.0; + + let _ = a + b * c; +} diff --git a/tests/ui/floating_point_mul_add.rs b/tests/ui/floating_point_mul_add.rs index 262a20f0f55..b5e4a8db4db 100644 --- a/tests/ui/floating_point_mul_add.rs +++ b/tests/ui/floating_point_mul_add.rs @@ -39,3 +39,21 @@ fn main() { // Cases where the lint shouldn't be applied let _ = (a * a + b * b).sqrt(); } + +fn _issue11831() { + struct NotAFloat; + + impl std::ops::Add<f64> for NotAFloat { + type Output = Self; + + fn add(self, _: f64) -> Self { + NotAFloat + } + } + + let a = NotAFloat; + let b = 1.0_f64; + let c = 1.0; + + let _ = a + b * c; +} |
