Run rust-fix on tests

This commit is contained in:
Krishna Sai Veera Reddy 2020-02-22 20:32:13 -08:00
parent bc706e3ba9
commit 454e505c12
9 changed files with 205 additions and 54 deletions

View file

@ -0,0 +1,18 @@
// run-rustfix
#![warn(clippy::suboptimal_flops)]
fn main() {
let x = 2f32;
let _ = x.exp_m1();
let _ = x.exp_m1() + 2.0;
// Cases where the lint shouldn't be applied
let _ = x.exp() - 2.0;
let _ = x.exp() - 1.0 * 2.0;
let x = 2f64;
let _ = x.exp_m1();
let _ = x.exp_m1() + 2.0;
// Cases where the lint shouldn't be applied
let _ = x.exp() - 2.0;
let _ = x.exp() - 1.0 * 2.0;
}

View file

@ -1,3 +1,4 @@
// run-rustfix
#![warn(clippy::suboptimal_flops)]
fn main() {

View file

@ -1,5 +1,5 @@
error: (e.pow(x) - 1) can be computed more accurately
--> $DIR/floating_point_exp.rs:5:13
--> $DIR/floating_point_exp.rs:6:13
|
LL | let _ = x.exp() - 1.0;
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
@ -7,19 +7,19 @@ LL | let _ = x.exp() - 1.0;
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
error: (e.pow(x) - 1) can be computed more accurately
--> $DIR/floating_point_exp.rs:6:13
--> $DIR/floating_point_exp.rs:7:13
|
LL | let _ = x.exp() - 1.0 + 2.0;
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
error: (e.pow(x) - 1) can be computed more accurately
--> $DIR/floating_point_exp.rs:12:13
--> $DIR/floating_point_exp.rs:13:13
|
LL | let _ = x.exp() - 1.0;
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
error: (e.pow(x) - 1) can be computed more accurately
--> $DIR/floating_point_exp.rs:13:13
--> $DIR/floating_point_exp.rs:14:13
|
LL | let _ = x.exp() - 1.0 + 2.0;
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`

View file

@ -0,0 +1,58 @@
// run-rustfix
#![allow(dead_code, clippy::double_parens)]
#![warn(clippy::suboptimal_flops)]
const TWO: f32 = 2.0;
const E: f32 = std::f32::consts::E;
fn check_log_base() {
let x = 1f32;
let _ = x.log2();
let _ = x.log10();
let _ = x.ln();
let _ = x.log2();
let _ = x.ln();
let x = 1f64;
let _ = x.log2();
let _ = x.log10();
let _ = x.ln();
}
fn check_ln1p() {
let x = 1f32;
let _ = 2.0f32.ln_1p();
let _ = 2.0f32.ln_1p();
let _ = x.ln_1p();
let _ = (x * 2.0).ln_1p();
let _ = x.powi(2).ln_1p();
let _ = (x.powi(2) * 2.0).ln_1p();
let _ = ((std::f32::consts::E - 1.0)).ln_1p();
let _ = x.ln_1p();
let _ = x.powi(2).ln_1p();
let _ = (x + 2.0).ln_1p();
let _ = (x * 2.0).ln_1p();
// Cases where the lint shouldn't be applied
let _ = (1.0 + x + 2.0).ln();
let _ = (x + 1.0 + 2.0).ln();
let _ = (x + 1.0 * 2.0).ln();
let _ = (1.0 + x - 2.0).ln();
let x = 1f64;
let _ = 2.0f64.ln_1p();
let _ = 2.0f64.ln_1p();
let _ = x.ln_1p();
let _ = (x * 2.0).ln_1p();
let _ = x.powi(2).ln_1p();
let _ = x.ln_1p();
let _ = x.powi(2).ln_1p();
let _ = (x + 2.0).ln_1p();
let _ = (x * 2.0).ln_1p();
// Cases where the lint shouldn't be applied
let _ = (1.0 + x + 2.0).ln();
let _ = (x + 1.0 + 2.0).ln();
let _ = (x + 1.0 * 2.0).ln();
let _ = (1.0 + x - 2.0).ln();
}
fn main() {}

View file

@ -1,4 +1,5 @@
#![allow(dead_code)]
// run-rustfix
#![allow(dead_code, clippy::double_parens)]
#![warn(clippy::suboptimal_flops)]
const TWO: f32 = 2.0;

View file

@ -1,5 +1,5 @@
error: logarithm for bases 2, 10 and e can be computed more accurately
--> $DIR/floating_point_log.rs:9:13
--> $DIR/floating_point_log.rs:10:13
|
LL | let _ = x.log(2f32);
| ^^^^^^^^^^^ help: consider using: `x.log2()`
@ -7,163 +7,163 @@ LL | let _ = x.log(2f32);
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
error: logarithm for bases 2, 10 and e can be computed more accurately
--> $DIR/floating_point_log.rs:10:13
--> $DIR/floating_point_log.rs:11:13
|
LL | let _ = x.log(10f32);
| ^^^^^^^^^^^^ help: consider using: `x.log10()`
error: logarithm for bases 2, 10 and e can be computed more accurately
--> $DIR/floating_point_log.rs:11:13
--> $DIR/floating_point_log.rs:12:13
|
LL | let _ = x.log(std::f32::consts::E);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()`
error: logarithm for bases 2, 10 and e can be computed more accurately
--> $DIR/floating_point_log.rs:12:13
--> $DIR/floating_point_log.rs:13:13
|
LL | let _ = x.log(TWO);
| ^^^^^^^^^^ help: consider using: `x.log2()`
error: logarithm for bases 2, 10 and e can be computed more accurately
--> $DIR/floating_point_log.rs:13:13
--> $DIR/floating_point_log.rs:14:13
|
LL | let _ = x.log(E);
| ^^^^^^^^ help: consider using: `x.ln()`
error: logarithm for bases 2, 10 and e can be computed more accurately
--> $DIR/floating_point_log.rs:16:13
--> $DIR/floating_point_log.rs:17:13
|
LL | let _ = x.log(2f64);
| ^^^^^^^^^^^ help: consider using: `x.log2()`
error: logarithm for bases 2, 10 and e can be computed more accurately
--> $DIR/floating_point_log.rs:17:13
--> $DIR/floating_point_log.rs:18:13
|
LL | let _ = x.log(10f64);
| ^^^^^^^^^^^^ help: consider using: `x.log10()`
error: logarithm for bases 2, 10 and e can be computed more accurately
--> $DIR/floating_point_log.rs:18:13
--> $DIR/floating_point_log.rs:19:13
|
LL | let _ = x.log(std::f64::consts::E);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:23:13
--> $DIR/floating_point_log.rs:24:13
|
LL | let _ = (1f32 + 2.).ln();
| ^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:24:13
--> $DIR/floating_point_log.rs:25:13
|
LL | let _ = (1f32 + 2.0).ln();
| ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:25:13
--> $DIR/floating_point_log.rs:26:13
|
LL | let _ = (1.0 + x).ln();
| ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:26:13
--> $DIR/floating_point_log.rs:27:13
|
LL | let _ = (1.0 + x * 2.0).ln();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x * 2.0).ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:27:13
--> $DIR/floating_point_log.rs:28:13
|
LL | let _ = (1.0 + x.powi(2)).ln();
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2).ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:28:13
--> $DIR/floating_point_log.rs:29:13
|
LL | let _ = (1.0 + x.powi(2) * 2.0).ln();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x.powi(2) * 2.0).ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:29:13
--> $DIR/floating_point_log.rs:30:13
|
LL | let _ = (1.0 + (std::f32::consts::E - 1.0)).ln();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `((std::f32::consts::E - 1.0)).ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:30:13
--> $DIR/floating_point_log.rs:31:13
|
LL | let _ = (x + 1.0).ln();
| ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:31:13
--> $DIR/floating_point_log.rs:32:13
|
LL | let _ = (x.powi(2) + 1.0).ln();
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2).ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:32:13
--> $DIR/floating_point_log.rs:33:13
|
LL | let _ = (x + 2.0 + 1.0).ln();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 2.0).ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:33:13
--> $DIR/floating_point_log.rs:34:13
|
LL | let _ = (x * 2.0 + 1.0).ln();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x * 2.0).ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:41:13
--> $DIR/floating_point_log.rs:42:13
|
LL | let _ = (1f64 + 2.).ln();
| ^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:42:13
--> $DIR/floating_point_log.rs:43:13
|
LL | let _ = (1f64 + 2.0).ln();
| ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:43:13
--> $DIR/floating_point_log.rs:44:13
|
LL | let _ = (1.0 + x).ln();
| ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:44:13
--> $DIR/floating_point_log.rs:45:13
|
LL | let _ = (1.0 + x * 2.0).ln();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x * 2.0).ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:45:13
--> $DIR/floating_point_log.rs:46:13
|
LL | let _ = (1.0 + x.powi(2)).ln();
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2).ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:46:13
--> $DIR/floating_point_log.rs:47:13
|
LL | let _ = (x + 1.0).ln();
| ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:47:13
--> $DIR/floating_point_log.rs:48:13
|
LL | let _ = (x.powi(2) + 1.0).ln();
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2).ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:48:13
--> $DIR/floating_point_log.rs:49:13
|
LL | let _ = (x + 2.0 + 1.0).ln();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 2.0).ln_1p()`
error: ln(1 + x) can be computed more accurately
--> $DIR/floating_point_log.rs:49:13
--> $DIR/floating_point_log.rs:50:13
|
LL | let _ = (x * 2.0 + 1.0).ln();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x * 2.0).ln_1p()`

View file

@ -0,0 +1,40 @@
// run-rustfix
#![warn(clippy::suboptimal_flops)]
fn main() {
let x = 3f32;
let _ = x.exp2();
let _ = 3.1f32.exp2();
let _ = (-3.1f32).exp2();
let _ = x.exp();
let _ = 3.1f32.exp();
let _ = (-3.1f32).exp();
let _ = x.sqrt();
let _ = x.cbrt();
let _ = x.powi(2);
let _ = x.powi(-2);
let _ = x.powi(16_777_215);
let _ = x.powi(-16_777_215);
let _ = x.powf(2.1);
let _ = x.powf(-2.1);
let _ = x.powf(16_777_216.0);
let _ = x.powf(-16_777_216.0);
let x = 3f64;
let _ = x.exp2();
let _ = 3.1f64.exp2();
let _ = (-3.1f64).exp2();
let _ = x.exp();
let _ = 3.1f64.exp();
let _ = (-3.1f64).exp();
let _ = x.sqrt();
let _ = x.cbrt();
let _ = x.powi(2);
let _ = x.powi(-2);
let _ = x.powi(-2_147_483_648);
let _ = x.powi(2_147_483_647);
let _ = x.powf(2.1);
let _ = x.powf(-2.1);
let _ = x.powf(-2_147_483_649.0);
let _ = x.powf(2_147_483_648.0);
}

View file

@ -1,3 +1,4 @@
// run-rustfix
#![warn(clippy::suboptimal_flops)]
fn main() {
@ -12,8 +13,12 @@ fn main() {
let _ = x.powf(1.0 / 3.0);
let _ = x.powf(2.0);
let _ = x.powf(-2.0);
let _ = x.powf(16_777_215.0);
let _ = x.powf(-16_777_215.0);
let _ = x.powf(2.1);
let _ = x.powf(-2.1);
let _ = x.powf(16_777_216.0);
let _ = x.powf(-16_777_216.0);
let x = 3f64;
let _ = 2f64.powf(x);
@ -26,6 +31,10 @@ fn main() {
let _ = x.powf(1.0 / 3.0);
let _ = x.powf(2.0);
let _ = x.powf(-2.0);
let _ = x.powf(-2_147_483_648.0);
let _ = x.powf(2_147_483_647.0);
let _ = x.powf(2.1);
let _ = x.powf(-2.1);
let _ = x.powf(-2_147_483_649.0);
let _ = x.powf(2_147_483_648.0);
}

View file

@ -1,5 +1,5 @@
error: exponent for bases 2 and e can be computed more accurately
--> $DIR/floating_point_powf.rs:5:13
--> $DIR/floating_point_powf.rs:6:13
|
LL | let _ = 2f32.powf(x);
| ^^^^^^^^^^^^ help: consider using: `x.exp2()`
@ -7,118 +7,142 @@ LL | let _ = 2f32.powf(x);
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
error: exponent for bases 2 and e can be computed more accurately
--> $DIR/floating_point_powf.rs:6:13
--> $DIR/floating_point_powf.rs:7:13
|
LL | let _ = 2f32.powf(3.1);
| ^^^^^^^^^^^^^^ help: consider using: `3.1f32.exp2()`
error: exponent for bases 2 and e can be computed more accurately
--> $DIR/floating_point_powf.rs:7:13
--> $DIR/floating_point_powf.rs:8:13
|
LL | let _ = 2f32.powf(-3.1);
| ^^^^^^^^^^^^^^^ help: consider using: `(-3.1f32).exp2()`
error: exponent for bases 2 and e can be computed more accurately
--> $DIR/floating_point_powf.rs:8:13
--> $DIR/floating_point_powf.rs:9:13
|
LL | let _ = std::f32::consts::E.powf(x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()`
error: exponent for bases 2 and e can be computed more accurately
--> $DIR/floating_point_powf.rs:9:13
--> $DIR/floating_point_powf.rs:10:13
|
LL | let _ = std::f32::consts::E.powf(3.1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `3.1f32.exp()`
error: exponent for bases 2 and e can be computed more accurately
--> $DIR/floating_point_powf.rs:10:13
--> $DIR/floating_point_powf.rs:11:13
|
LL | let _ = std::f32::consts::E.powf(-3.1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-3.1f32).exp()`
error: square-root of a number can be computed more efficiently and accurately
--> $DIR/floating_point_powf.rs:11:13
--> $DIR/floating_point_powf.rs:12:13
|
LL | let _ = x.powf(1.0 / 2.0);
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()`
error: cube-root of a number can be computed more accurately
--> $DIR/floating_point_powf.rs:12:13
--> $DIR/floating_point_powf.rs:13:13
|
LL | let _ = x.powf(1.0 / 3.0);
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()`
error: exponentiation with integer powers can be computed more efficiently
--> $DIR/floating_point_powf.rs:13:13
--> $DIR/floating_point_powf.rs:14:13
|
LL | let _ = x.powf(2.0);
| ^^^^^^^^^^^ help: consider using: `x.powi(2)`
error: exponentiation with integer powers can be computed more efficiently
--> $DIR/floating_point_powf.rs:14:13
--> $DIR/floating_point_powf.rs:15:13
|
LL | let _ = x.powf(-2.0);
| ^^^^^^^^^^^^ help: consider using: `x.powi(-2)`
error: exponentiation with integer powers can be computed more efficiently
--> $DIR/floating_point_powf.rs:16:13
|
LL | let _ = x.powf(16_777_215.0);
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(16_777_215)`
error: exponentiation with integer powers can be computed more efficiently
--> $DIR/floating_point_powf.rs:17:13
|
LL | let _ = x.powf(-16_777_215.0);
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(-16_777_215)`
error: exponent for bases 2 and e can be computed more accurately
--> $DIR/floating_point_powf.rs:19:13
--> $DIR/floating_point_powf.rs:24:13
|
LL | let _ = 2f64.powf(x);
| ^^^^^^^^^^^^ help: consider using: `x.exp2()`
error: exponent for bases 2 and e can be computed more accurately
--> $DIR/floating_point_powf.rs:20:13
--> $DIR/floating_point_powf.rs:25:13
|
LL | let _ = 2f64.powf(3.1);
| ^^^^^^^^^^^^^^ help: consider using: `3.1f64.exp2()`
error: exponent for bases 2 and e can be computed more accurately
--> $DIR/floating_point_powf.rs:21:13
--> $DIR/floating_point_powf.rs:26:13
|
LL | let _ = 2f64.powf(-3.1);
| ^^^^^^^^^^^^^^^ help: consider using: `(-3.1f64).exp2()`
error: exponent for bases 2 and e can be computed more accurately
--> $DIR/floating_point_powf.rs:22:13
--> $DIR/floating_point_powf.rs:27:13
|
LL | let _ = std::f64::consts::E.powf(x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()`
error: exponent for bases 2 and e can be computed more accurately
--> $DIR/floating_point_powf.rs:23:13
--> $DIR/floating_point_powf.rs:28:13
|
LL | let _ = std::f64::consts::E.powf(3.1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `3.1f64.exp()`
error: exponent for bases 2 and e can be computed more accurately
--> $DIR/floating_point_powf.rs:24:13
--> $DIR/floating_point_powf.rs:29:13
|
LL | let _ = std::f64::consts::E.powf(-3.1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-3.1f64).exp()`
error: square-root of a number can be computed more efficiently and accurately
--> $DIR/floating_point_powf.rs:25:13
--> $DIR/floating_point_powf.rs:30:13
|
LL | let _ = x.powf(1.0 / 2.0);
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()`
error: cube-root of a number can be computed more accurately
--> $DIR/floating_point_powf.rs:26:13
--> $DIR/floating_point_powf.rs:31:13
|
LL | let _ = x.powf(1.0 / 3.0);
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()`
error: exponentiation with integer powers can be computed more efficiently
--> $DIR/floating_point_powf.rs:27:13
--> $DIR/floating_point_powf.rs:32:13
|
LL | let _ = x.powf(2.0);
| ^^^^^^^^^^^ help: consider using: `x.powi(2)`
error: exponentiation with integer powers can be computed more efficiently
--> $DIR/floating_point_powf.rs:28:13
--> $DIR/floating_point_powf.rs:33:13
|
LL | let _ = x.powf(-2.0);
| ^^^^^^^^^^^^ help: consider using: `x.powi(-2)`
error: aborting due to 20 previous errors
error: exponentiation with integer powers can be computed more efficiently
--> $DIR/floating_point_powf.rs:34:13
|
LL | let _ = x.powf(-2_147_483_648.0);
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(-2_147_483_648)`
error: exponentiation with integer powers can be computed more efficiently
--> $DIR/floating_point_powf.rs:35:13
|
LL | let _ = x.powf(2_147_483_647.0);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2_147_483_647)`
error: aborting due to 24 previous errors