Skip to content

Commit 9028173

Browse files
committed
Auto merge of rust-lang#7201 - mucinoab:master, r=giraffate
Remove powi, "square can be computed more efficiently" powi(2) produces exactly the same native code as x * x powi was part of the [`suboptimal_flops`] lint fixes rust-lang#7058 changelog: Remove powi [`suboptimal_flops`], "square can be computed more efficiently"
2 parents 6fcdb8a + be540e6 commit 9028173

File tree

4 files changed

+18
-38
lines changed

4 files changed

+18
-38
lines changed

clippy_lints/src/floating_point_arithmetic.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
323323
cx,
324324
SUBOPTIMAL_FLOPS,
325325
parent.span,
326-
"square can be computed more efficiently",
326+
"multiply and add expressions can be calculated more efficiently and accurately",
327327
"consider using",
328328
format!(
329329
"{}.mul_add({}, {})",
@@ -337,16 +337,6 @@ fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
337337
return;
338338
}
339339
}
340-
341-
span_lint_and_sugg(
342-
cx,
343-
SUBOPTIMAL_FLOPS,
344-
expr.span,
345-
"square can be computed more efficiently",
346-
"consider using",
347-
format!("{} * {}", Sugg::hir(cx, &args[0], ".."), Sugg::hir(cx, &args[0], "..")),
348-
Applicability::MachineApplicable,
349-
);
350340
}
351341
}
352342
}

tests/ui/floating_point_powi.fixed

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
fn main() {
55
let one = 1;
66
let x = 3f32;
7-
let _ = x * x;
8-
let _ = x * x;
97

108
let y = 4f32;
119
let _ = x.mul_add(x, y);
1210
let _ = y.mul_add(y, x);
1311
let _ = x.mul_add(x, y).sqrt();
1412
let _ = y.mul_add(y, x).sqrt();
1513
// Cases where the lint shouldn't be applied
14+
let _ = x.powi(2);
15+
let _ = x.powi(1 + 1);
1616
let _ = x.powi(3);
17+
let _ = x.powi(4) + y;
1718
let _ = x.powi(one + 1);
1819
let _ = (x.powi(2) + y.powi(2)).sqrt();
1920
}

tests/ui/floating_point_powi.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
fn main() {
55
let one = 1;
66
let x = 3f32;
7-
let _ = x.powi(2);
8-
let _ = x.powi(1 + 1);
97

108
let y = 4f32;
119
let _ = x.powi(2) + y;
1210
let _ = x + y.powi(2);
1311
let _ = (x.powi(2) + y).sqrt();
1412
let _ = (x + y.powi(2)).sqrt();
1513
// Cases where the lint shouldn't be applied
14+
let _ = x.powi(2);
15+
let _ = x.powi(1 + 1);
1616
let _ = x.powi(3);
17+
let _ = x.powi(4) + y;
1718
let _ = x.powi(one + 1);
1819
let _ = (x.powi(2) + y.powi(2)).sqrt();
1920
}

tests/ui/floating_point_powi.stderr

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,28 @@
1-
error: square can be computed more efficiently
2-
--> $DIR/floating_point_powi.rs:7:13
3-
|
4-
LL | let _ = x.powi(2);
5-
| ^^^^^^^^^ help: consider using: `x * x`
6-
|
7-
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
8-
9-
error: square can be computed more efficiently
10-
--> $DIR/floating_point_powi.rs:8:13
11-
|
12-
LL | let _ = x.powi(1 + 1);
13-
| ^^^^^^^^^^^^^ help: consider using: `x * x`
14-
15-
error: square can be computed more efficiently
16-
--> $DIR/floating_point_powi.rs:11:13
1+
error: multiply and add expressions can be calculated more efficiently and accurately
2+
--> $DIR/floating_point_powi.rs:9:13
173
|
184
LL | let _ = x.powi(2) + y;
195
| ^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, y)`
6+
|
7+
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
208

21-
error: square can be computed more efficiently
22-
--> $DIR/floating_point_powi.rs:12:13
9+
error: multiply and add expressions can be calculated more efficiently and accurately
10+
--> $DIR/floating_point_powi.rs:10:13
2311
|
2412
LL | let _ = x + y.powi(2);
2513
| ^^^^^^^^^^^^^ help: consider using: `y.mul_add(y, x)`
2614

27-
error: square can be computed more efficiently
28-
--> $DIR/floating_point_powi.rs:13:13
15+
error: multiply and add expressions can be calculated more efficiently and accurately
16+
--> $DIR/floating_point_powi.rs:11:13
2917
|
3018
LL | let _ = (x.powi(2) + y).sqrt();
3119
| ^^^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, y)`
3220

33-
error: square can be computed more efficiently
34-
--> $DIR/floating_point_powi.rs:14:13
21+
error: multiply and add expressions can be calculated more efficiently and accurately
22+
--> $DIR/floating_point_powi.rs:12:13
3523
|
3624
LL | let _ = (x + y.powi(2)).sqrt();
3725
| ^^^^^^^^^^^^^^^ help: consider using: `y.mul_add(y, x)`
3826

39-
error: aborting due to 6 previous errors
27+
error: aborting due to 4 previous errors
4028

0 commit comments

Comments
 (0)