mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 07:04:18 +00:00
Automatic generation of error annotations for ui tests
This commit is contained in:
parent
3a31c05578
commit
a05d3a4137
729 changed files with 6917 additions and 2954 deletions
|
@ -12,27 +12,46 @@ fn main() {
|
|||
const Z: u32 = 0;
|
||||
let u: u32 = 42;
|
||||
u <= 0;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
u <= Z;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
u < Z;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
Z >= u;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
Z > u;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
u > u32::MAX;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
u >= u32::MAX;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
u32::MAX < u;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
u32::MAX <= u;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
1-1 > u;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
u >= !0;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
u <= 12 - 2*6;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
let i: i8 = 0;
|
||||
i < -127 - 1;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
i8::MAX >= i;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
3-7 < i32::MIN;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
let b = false;
|
||||
b >= true;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
false > b;
|
||||
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
|
||||
u > 0; // ok
|
||||
// this is handled by clippy::unit_cmp
|
||||
() < {};
|
||||
//~^ ERROR: <-comparison of unit values detected. This will always be false
|
||||
//~| NOTE: `#[deny(clippy::unit_cmp)]` on by default
|
||||
}
|
||||
|
||||
use std::cmp::{Ordering, PartialEq, PartialOrd};
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | u <= 0;
|
|||
= note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings`
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:15:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:16:5
|
||||
|
|
||||
LL | u <= Z;
|
||||
| ^^^^^^
|
||||
|
@ -16,7 +16,7 @@ LL | u <= Z;
|
|||
= help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == Z` instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:16:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:18:5
|
||||
|
|
||||
LL | u < Z;
|
||||
| ^^^^^
|
||||
|
@ -24,7 +24,7 @@ LL | u < Z;
|
|||
= help: because `Z` is the minimum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:17:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:20:5
|
||||
|
|
||||
LL | Z >= u;
|
||||
| ^^^^^^
|
||||
|
@ -32,7 +32,7 @@ LL | Z >= u;
|
|||
= help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `Z == u` instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:18:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:22:5
|
||||
|
|
||||
LL | Z > u;
|
||||
| ^^^^^
|
||||
|
@ -40,7 +40,7 @@ LL | Z > u;
|
|||
= help: because `Z` is the minimum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:19:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:24:5
|
||||
|
|
||||
LL | u > u32::MAX;
|
||||
| ^^^^^^^^^^^^
|
||||
|
@ -48,7 +48,7 @@ LL | u > u32::MAX;
|
|||
= help: because `u32::MAX` is the maximum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:20:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:26:5
|
||||
|
|
||||
LL | u >= u32::MAX;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -56,7 +56,7 @@ LL | u >= u32::MAX;
|
|||
= help: because `u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == u32::MAX` instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:21:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:28:5
|
||||
|
|
||||
LL | u32::MAX < u;
|
||||
| ^^^^^^^^^^^^
|
||||
|
@ -64,7 +64,7 @@ LL | u32::MAX < u;
|
|||
= help: because `u32::MAX` is the maximum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:22:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:30:5
|
||||
|
|
||||
LL | u32::MAX <= u;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -72,7 +72,7 @@ LL | u32::MAX <= u;
|
|||
= help: because `u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u32::MAX == u` instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:23:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:32:5
|
||||
|
|
||||
LL | 1-1 > u;
|
||||
| ^^^^^^^
|
||||
|
@ -80,7 +80,7 @@ LL | 1-1 > u;
|
|||
= help: because `1-1` is the minimum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:24:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:34:5
|
||||
|
|
||||
LL | u >= !0;
|
||||
| ^^^^^^^
|
||||
|
@ -88,7 +88,7 @@ LL | u >= !0;
|
|||
= help: because `!0` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == !0` instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:25:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:36:5
|
||||
|
|
||||
LL | u <= 12 - 2*6;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -96,7 +96,7 @@ LL | u <= 12 - 2*6;
|
|||
= help: because `12 - 2*6` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == 12 - 2*6` instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:27:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:39:5
|
||||
|
|
||||
LL | i < -127 - 1;
|
||||
| ^^^^^^^^^^^^
|
||||
|
@ -104,7 +104,7 @@ LL | i < -127 - 1;
|
|||
= help: because `-127 - 1` is the minimum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:28:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:41:5
|
||||
|
|
||||
LL | i8::MAX >= i;
|
||||
| ^^^^^^^^^^^^
|
||||
|
@ -112,7 +112,7 @@ LL | i8::MAX >= i;
|
|||
= help: because `i8::MAX` is the maximum value for this type, this comparison is always true
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:29:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:43:5
|
||||
|
|
||||
LL | 3-7 < i32::MIN;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
@ -120,7 +120,7 @@ LL | 3-7 < i32::MIN;
|
|||
= help: because `i32::MIN` is the minimum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:31:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:46:5
|
||||
|
|
||||
LL | b >= true;
|
||||
| ^^^^^^^^^
|
||||
|
@ -128,7 +128,7 @@ LL | b >= true;
|
|||
= help: because `true` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `b == true` instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:32:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:48:5
|
||||
|
|
||||
LL | false > b;
|
||||
| ^^^^^^^^^
|
||||
|
@ -136,7 +136,7 @@ LL | false > b;
|
|||
= help: because `false` is the minimum value for this type, this comparison is always false
|
||||
|
||||
error: <-comparison of unit values detected. This will always be false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:35:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:52:5
|
||||
|
|
||||
LL | () < {};
|
||||
| ^^^^^^^
|
||||
|
|
|
@ -2,63 +2,86 @@
|
|||
#[allow(clippy::similar_names)]
|
||||
fn main() {
|
||||
let my_e = 2.7182;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::E` found
|
||||
let almost_e = 2.718;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::E` found
|
||||
let no_e = 2.71;
|
||||
|
||||
let my_1_frac_pi = 0.3183;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_PI` found
|
||||
let no_1_frac_pi = 0.31;
|
||||
|
||||
let my_frac_1_sqrt_2 = 0.70710678;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found
|
||||
let almost_frac_1_sqrt_2 = 0.70711;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found
|
||||
let my_frac_1_sqrt_2 = 0.707;
|
||||
|
||||
let my_frac_2_pi = 0.63661977;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_2_PI` found
|
||||
let no_frac_2_pi = 0.636;
|
||||
|
||||
let my_frac_2_sq_pi = 1.128379;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found
|
||||
let no_frac_2_sq_pi = 1.128;
|
||||
|
||||
let my_frac_pi_2 = 1.57079632679;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_2` found
|
||||
let no_frac_pi_2 = 1.5705;
|
||||
|
||||
let my_frac_pi_3 = 1.04719755119;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_3` found
|
||||
let no_frac_pi_3 = 1.047;
|
||||
|
||||
let my_frac_pi_4 = 0.785398163397;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_4` found
|
||||
let no_frac_pi_4 = 0.785;
|
||||
|
||||
let my_frac_pi_6 = 0.523598775598;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_6` found
|
||||
let no_frac_pi_6 = 0.523;
|
||||
|
||||
let my_frac_pi_8 = 0.3926990816987;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_8` found
|
||||
let no_frac_pi_8 = 0.392;
|
||||
|
||||
let my_ln_10 = 2.302585092994046;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::LN_10` found
|
||||
let no_ln_10 = 2.303;
|
||||
|
||||
let my_ln_2 = 0.6931471805599453;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::LN_2` found
|
||||
let no_ln_2 = 0.693;
|
||||
|
||||
let my_log10_e = 0.4342944819032518;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::LOG10_E` found
|
||||
let no_log10_e = 0.434;
|
||||
|
||||
let my_log2_e = 1.4426950408889634;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_E` found
|
||||
let no_log2_e = 1.442;
|
||||
|
||||
let log2_10 = 3.321928094887362;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found
|
||||
let no_log2_10 = 3.321;
|
||||
|
||||
let log10_2 = 0.301029995663981;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::LOG10_2` found
|
||||
let no_log10_2 = 0.301;
|
||||
|
||||
let my_pi = 3.1415;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::PI` found
|
||||
let almost_pi = 3.14;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::PI` found
|
||||
let no_pi = 3.15;
|
||||
|
||||
let my_sq2 = 1.4142;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::SQRT_2` found
|
||||
let no_sq2 = 1.414;
|
||||
|
||||
let my_tau = 6.2832;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::TAU` found
|
||||
let almost_tau = 6.28;
|
||||
//~^ ERROR: approximate value of `f{32, 64}::consts::TAU` found
|
||||
let no_tau = 6.3;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | let my_e = 2.7182;
|
|||
= note: `-D clippy::approx-constant` implied by `-D warnings`
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::E` found
|
||||
--> $DIR/approx_const.rs:5:20
|
||||
--> $DIR/approx_const.rs:6:20
|
||||
|
|
||||
LL | let almost_e = 2.718;
|
||||
| ^^^^^
|
||||
|
@ -16,7 +16,7 @@ LL | let almost_e = 2.718;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_1_PI` found
|
||||
--> $DIR/approx_const.rs:8:24
|
||||
--> $DIR/approx_const.rs:10:24
|
||||
|
|
||||
LL | let my_1_frac_pi = 0.3183;
|
||||
| ^^^^^^
|
||||
|
@ -24,7 +24,7 @@ LL | let my_1_frac_pi = 0.3183;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found
|
||||
--> $DIR/approx_const.rs:11:28
|
||||
--> $DIR/approx_const.rs:14:28
|
||||
|
|
||||
LL | let my_frac_1_sqrt_2 = 0.70710678;
|
||||
| ^^^^^^^^^^
|
||||
|
@ -32,7 +32,7 @@ LL | let my_frac_1_sqrt_2 = 0.70710678;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found
|
||||
--> $DIR/approx_const.rs:12:32
|
||||
--> $DIR/approx_const.rs:16:32
|
||||
|
|
||||
LL | let almost_frac_1_sqrt_2 = 0.70711;
|
||||
| ^^^^^^^
|
||||
|
@ -40,7 +40,7 @@ LL | let almost_frac_1_sqrt_2 = 0.70711;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_2_PI` found
|
||||
--> $DIR/approx_const.rs:15:24
|
||||
--> $DIR/approx_const.rs:20:24
|
||||
|
|
||||
LL | let my_frac_2_pi = 0.63661977;
|
||||
| ^^^^^^^^^^
|
||||
|
@ -48,7 +48,7 @@ LL | let my_frac_2_pi = 0.63661977;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found
|
||||
--> $DIR/approx_const.rs:18:27
|
||||
--> $DIR/approx_const.rs:24:27
|
||||
|
|
||||
LL | let my_frac_2_sq_pi = 1.128379;
|
||||
| ^^^^^^^^
|
||||
|
@ -56,7 +56,7 @@ LL | let my_frac_2_sq_pi = 1.128379;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_PI_2` found
|
||||
--> $DIR/approx_const.rs:21:24
|
||||
--> $DIR/approx_const.rs:28:24
|
||||
|
|
||||
LL | let my_frac_pi_2 = 1.57079632679;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -64,7 +64,7 @@ LL | let my_frac_pi_2 = 1.57079632679;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_PI_3` found
|
||||
--> $DIR/approx_const.rs:24:24
|
||||
--> $DIR/approx_const.rs:32:24
|
||||
|
|
||||
LL | let my_frac_pi_3 = 1.04719755119;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -72,7 +72,7 @@ LL | let my_frac_pi_3 = 1.04719755119;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_PI_4` found
|
||||
--> $DIR/approx_const.rs:27:24
|
||||
--> $DIR/approx_const.rs:36:24
|
||||
|
|
||||
LL | let my_frac_pi_4 = 0.785398163397;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
@ -80,7 +80,7 @@ LL | let my_frac_pi_4 = 0.785398163397;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_PI_6` found
|
||||
--> $DIR/approx_const.rs:30:24
|
||||
--> $DIR/approx_const.rs:40:24
|
||||
|
|
||||
LL | let my_frac_pi_6 = 0.523598775598;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
@ -88,7 +88,7 @@ LL | let my_frac_pi_6 = 0.523598775598;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_PI_8` found
|
||||
--> $DIR/approx_const.rs:33:24
|
||||
--> $DIR/approx_const.rs:44:24
|
||||
|
|
||||
LL | let my_frac_pi_8 = 0.3926990816987;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
@ -96,7 +96,7 @@ LL | let my_frac_pi_8 = 0.3926990816987;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::LN_10` found
|
||||
--> $DIR/approx_const.rs:36:20
|
||||
--> $DIR/approx_const.rs:48:20
|
||||
|
|
||||
LL | let my_ln_10 = 2.302585092994046;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
@ -104,7 +104,7 @@ LL | let my_ln_10 = 2.302585092994046;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::LN_2` found
|
||||
--> $DIR/approx_const.rs:39:19
|
||||
--> $DIR/approx_const.rs:52:19
|
||||
|
|
||||
LL | let my_ln_2 = 0.6931471805599453;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
@ -112,7 +112,7 @@ LL | let my_ln_2 = 0.6931471805599453;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::LOG10_E` found
|
||||
--> $DIR/approx_const.rs:42:22
|
||||
--> $DIR/approx_const.rs:56:22
|
||||
|
|
||||
LL | let my_log10_e = 0.4342944819032518;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
@ -120,7 +120,7 @@ LL | let my_log10_e = 0.4342944819032518;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::LOG2_E` found
|
||||
--> $DIR/approx_const.rs:45:21
|
||||
--> $DIR/approx_const.rs:60:21
|
||||
|
|
||||
LL | let my_log2_e = 1.4426950408889634;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
@ -128,7 +128,7 @@ LL | let my_log2_e = 1.4426950408889634;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::LOG2_10` found
|
||||
--> $DIR/approx_const.rs:48:19
|
||||
--> $DIR/approx_const.rs:64:19
|
||||
|
|
||||
LL | let log2_10 = 3.321928094887362;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
@ -136,7 +136,7 @@ LL | let log2_10 = 3.321928094887362;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::LOG10_2` found
|
||||
--> $DIR/approx_const.rs:51:19
|
||||
--> $DIR/approx_const.rs:68:19
|
||||
|
|
||||
LL | let log10_2 = 0.301029995663981;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
@ -144,7 +144,7 @@ LL | let log10_2 = 0.301029995663981;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::PI` found
|
||||
--> $DIR/approx_const.rs:54:17
|
||||
--> $DIR/approx_const.rs:72:17
|
||||
|
|
||||
LL | let my_pi = 3.1415;
|
||||
| ^^^^^^
|
||||
|
@ -152,7 +152,7 @@ LL | let my_pi = 3.1415;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::PI` found
|
||||
--> $DIR/approx_const.rs:55:21
|
||||
--> $DIR/approx_const.rs:74:21
|
||||
|
|
||||
LL | let almost_pi = 3.14;
|
||||
| ^^^^
|
||||
|
@ -160,7 +160,7 @@ LL | let almost_pi = 3.14;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::SQRT_2` found
|
||||
--> $DIR/approx_const.rs:58:18
|
||||
--> $DIR/approx_const.rs:78:18
|
||||
|
|
||||
LL | let my_sq2 = 1.4142;
|
||||
| ^^^^^^
|
||||
|
@ -168,7 +168,7 @@ LL | let my_sq2 = 1.4142;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::TAU` found
|
||||
--> $DIR/approx_const.rs:61:18
|
||||
--> $DIR/approx_const.rs:82:18
|
||||
|
|
||||
LL | let my_tau = 6.2832;
|
||||
| ^^^^^^
|
||||
|
@ -176,7 +176,7 @@ LL | let my_tau = 6.2832;
|
|||
= help: consider using the constant directly
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::TAU` found
|
||||
--> $DIR/approx_const.rs:62:22
|
||||
--> $DIR/approx_const.rs:84:22
|
||||
|
|
||||
LL | let almost_tau = 6.28;
|
||||
| ^^^^
|
||||
|
|
|
@ -20,7 +20,10 @@ impl<T> Covariant<T> {
|
|||
fn main() {
|
||||
let mut string = String::new();
|
||||
let _ = string.as_ptr() as *mut u8;
|
||||
//~^ ERROR: casting the result of `as_ptr` to *mut u8
|
||||
//~| NOTE: `-D clippy::as-ptr-cast-mut` implied by `-D warnings`
|
||||
let _: *mut i8 = string.as_ptr() as *mut _;
|
||||
//~^ ERROR: casting the result of `as_ptr` to *mut i8
|
||||
let _ = string.as_ptr() as *const i8;
|
||||
let _ = string.as_mut_ptr();
|
||||
let _ = string.as_mut_ptr() as *mut u8;
|
||||
|
|
|
@ -7,7 +7,7 @@ LL | let _ = string.as_ptr() as *mut u8;
|
|||
= note: `-D clippy::as-ptr-cast-mut` implied by `-D warnings`
|
||||
|
||||
error: casting the result of `as_ptr` to *mut i8
|
||||
--> $DIR/as_ptr_cast_mut.rs:23:22
|
||||
--> $DIR/as_ptr_cast_mut.rs:25:22
|
||||
|
|
||||
LL | let _: *mut i8 = string.as_ptr() as *mut _;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `string.as_mut_ptr()`
|
||||
|
|
|
@ -6,8 +6,11 @@ mod warn_intel {
|
|||
pub(super) unsafe fn use_asm() {
|
||||
use std::arch::asm;
|
||||
asm!("");
|
||||
//~^ ERROR: Intel x86 assembly syntax used
|
||||
asm!("", options());
|
||||
//~^ ERROR: Intel x86 assembly syntax used
|
||||
asm!("", options(nostack));
|
||||
//~^ ERROR: Intel x86 assembly syntax used
|
||||
asm!("", options(att_syntax));
|
||||
asm!("", options(nostack, att_syntax));
|
||||
}
|
||||
|
@ -21,7 +24,9 @@ mod warn_att {
|
|||
asm!("", options());
|
||||
asm!("", options(nostack));
|
||||
asm!("", options(att_syntax));
|
||||
//~^ ERROR: AT&T x86 assembly syntax used
|
||||
asm!("", options(nostack, att_syntax));
|
||||
//~^ ERROR: AT&T x86 assembly syntax used
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | asm!("");
|
|||
= note: `-D clippy::inline-asm-x86-intel-syntax` implied by `-D warnings`
|
||||
|
||||
error: Intel x86 assembly syntax used
|
||||
--> $DIR/asm_syntax.rs:9:9
|
||||
--> $DIR/asm_syntax.rs:10:9
|
||||
|
|
||||
LL | asm!("", options());
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -16,7 +16,7 @@ LL | asm!("", options());
|
|||
= help: use AT&T x86 assembly syntax
|
||||
|
||||
error: Intel x86 assembly syntax used
|
||||
--> $DIR/asm_syntax.rs:10:9
|
||||
--> $DIR/asm_syntax.rs:12:9
|
||||
|
|
||||
LL | asm!("", options(nostack));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -24,7 +24,7 @@ LL | asm!("", options(nostack));
|
|||
= help: use AT&T x86 assembly syntax
|
||||
|
||||
error: AT&T x86 assembly syntax used
|
||||
--> $DIR/asm_syntax.rs:23:9
|
||||
--> $DIR/asm_syntax.rs:26:9
|
||||
|
|
||||
LL | asm!("", options(att_syntax));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -33,7 +33,7 @@ LL | asm!("", options(att_syntax));
|
|||
= note: `-D clippy::inline-asm-x86-att-syntax` implied by `-D warnings`
|
||||
|
||||
error: AT&T x86 assembly syntax used
|
||||
--> $DIR/asm_syntax.rs:24:9
|
||||
--> $DIR/asm_syntax.rs:28:9
|
||||
|
|
||||
LL | asm!("", options(nostack, att_syntax));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -8,21 +8,30 @@ macro_rules! assert_const {
|
|||
}
|
||||
fn main() {
|
||||
assert!(true);
|
||||
//~^ ERROR: `assert!(true)` will be optimized out by the compiler
|
||||
assert!(false);
|
||||
//~^ ERROR: `assert!(false)` should probably be replaced
|
||||
assert!(true, "true message");
|
||||
//~^ ERROR: `assert!(true)` will be optimized out by the compiler
|
||||
assert!(false, "false message");
|
||||
//~^ ERROR: `assert!(false, ..)` should probably be replaced
|
||||
|
||||
let msg = "panic message";
|
||||
assert!(false, "{}", msg.to_uppercase());
|
||||
//~^ ERROR: `assert!(false, ..)` should probably be replaced
|
||||
|
||||
const B: bool = true;
|
||||
assert!(B);
|
||||
//~^ ERROR: `assert!(true)` will be optimized out by the compiler
|
||||
|
||||
const C: bool = false;
|
||||
assert!(C);
|
||||
//~^ ERROR: `assert!(false)` should probably be replaced
|
||||
assert!(C, "C message");
|
||||
//~^ ERROR: `assert!(false, ..)` should probably be replaced
|
||||
|
||||
debug_assert!(true);
|
||||
//~^ ERROR: `debug_assert!(true)` will be optimized out by the compiler
|
||||
// Don't lint this, since there is no better way for expressing "Only panic in debug mode".
|
||||
debug_assert!(false); // #3948
|
||||
assert_const!(3);
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | assert!(true);
|
|||
= note: `-D clippy::assertions-on-constants` implied by `-D warnings`
|
||||
|
||||
error: `assert!(false)` should probably be replaced
|
||||
--> $DIR/assertions_on_constants.rs:11:5
|
||||
--> $DIR/assertions_on_constants.rs:12:5
|
||||
|
|
||||
LL | assert!(false);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
@ -16,7 +16,7 @@ LL | assert!(false);
|
|||
= help: use `panic!()` or `unreachable!()`
|
||||
|
||||
error: `assert!(true)` will be optimized out by the compiler
|
||||
--> $DIR/assertions_on_constants.rs:12:5
|
||||
--> $DIR/assertions_on_constants.rs:14:5
|
||||
|
|
||||
LL | assert!(true, "true message");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -24,7 +24,7 @@ LL | assert!(true, "true message");
|
|||
= help: remove it
|
||||
|
||||
error: `assert!(false, ..)` should probably be replaced
|
||||
--> $DIR/assertions_on_constants.rs:13:5
|
||||
--> $DIR/assertions_on_constants.rs:16:5
|
||||
|
|
||||
LL | assert!(false, "false message");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -32,7 +32,7 @@ LL | assert!(false, "false message");
|
|||
= help: use `panic!(..)` or `unreachable!(..)`
|
||||
|
||||
error: `assert!(false, ..)` should probably be replaced
|
||||
--> $DIR/assertions_on_constants.rs:16:5
|
||||
--> $DIR/assertions_on_constants.rs:20:5
|
||||
|
|
||||
LL | assert!(false, "{}", msg.to_uppercase());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -40,7 +40,7 @@ LL | assert!(false, "{}", msg.to_uppercase());
|
|||
= help: use `panic!(..)` or `unreachable!(..)`
|
||||
|
||||
error: `assert!(true)` will be optimized out by the compiler
|
||||
--> $DIR/assertions_on_constants.rs:19:5
|
||||
--> $DIR/assertions_on_constants.rs:24:5
|
||||
|
|
||||
LL | assert!(B);
|
||||
| ^^^^^^^^^^
|
||||
|
@ -48,7 +48,7 @@ LL | assert!(B);
|
|||
= help: remove it
|
||||
|
||||
error: `assert!(false)` should probably be replaced
|
||||
--> $DIR/assertions_on_constants.rs:22:5
|
||||
--> $DIR/assertions_on_constants.rs:28:5
|
||||
|
|
||||
LL | assert!(C);
|
||||
| ^^^^^^^^^^
|
||||
|
@ -56,7 +56,7 @@ LL | assert!(C);
|
|||
= help: use `panic!()` or `unreachable!()`
|
||||
|
||||
error: `assert!(false, ..)` should probably be replaced
|
||||
--> $DIR/assertions_on_constants.rs:23:5
|
||||
--> $DIR/assertions_on_constants.rs:30:5
|
||||
|
|
||||
LL | assert!(C, "C message");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -64,7 +64,7 @@ LL | assert!(C, "C message");
|
|||
= help: use `panic!(..)` or `unreachable!(..)`
|
||||
|
||||
error: `debug_assert!(true)` will be optimized out by the compiler
|
||||
--> $DIR/assertions_on_constants.rs:25:5
|
||||
--> $DIR/assertions_on_constants.rs:33:5
|
||||
|
|
||||
LL | debug_assert!(true);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -6,14 +6,24 @@
|
|||
fn main() {
|
||||
let mut a = 5;
|
||||
a += a + 1;
|
||||
//~^ ERROR: variable appears on both sides of an assignment operation
|
||||
//~| NOTE: `-D clippy::misrefactored-assign-op` implied by `-D warnings`
|
||||
a += 1 + a;
|
||||
//~^ ERROR: variable appears on both sides of an assignment operation
|
||||
a -= a - 1;
|
||||
//~^ ERROR: variable appears on both sides of an assignment operation
|
||||
a *= a * 99;
|
||||
//~^ ERROR: variable appears on both sides of an assignment operation
|
||||
a *= 42 * a;
|
||||
//~^ ERROR: variable appears on both sides of an assignment operation
|
||||
a /= a / 2;
|
||||
//~^ ERROR: variable appears on both sides of an assignment operation
|
||||
a %= a % 5;
|
||||
//~^ ERROR: variable appears on both sides of an assignment operation
|
||||
a &= a & 1;
|
||||
//~^ ERROR: variable appears on both sides of an assignment operation
|
||||
a *= a * a;
|
||||
//~^ ERROR: variable appears on both sides of an assignment operation
|
||||
a = a * a * a;
|
||||
a = a * 42 * a;
|
||||
a = a * 2 + a;
|
||||
|
@ -51,6 +61,8 @@ fn cow_add_assign() {
|
|||
|
||||
// this can be linted
|
||||
buf = buf + cows.clone();
|
||||
//~^ ERROR: manual implementation of an assign operation
|
||||
//~| NOTE: `-D clippy::assign-op-pattern` implied by `-D warnings`
|
||||
|
||||
// this should not as cow<str> Add is not commutative
|
||||
buf = cows + buf;
|
||||
|
|
|
@ -15,7 +15,7 @@ LL | a = a + a + 1;
|
|||
| ~~~~~~~~~~~~~
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:9:5
|
||||
--> $DIR/assign_ops2.rs:11:5
|
||||
|
|
||||
LL | a += 1 + a;
|
||||
| ^^^^^^^^^^
|
||||
|
@ -30,7 +30,7 @@ LL | a = a + 1 + a;
|
|||
| ~~~~~~~~~~~~~
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:10:5
|
||||
--> $DIR/assign_ops2.rs:13:5
|
||||
|
|
||||
LL | a -= a - 1;
|
||||
| ^^^^^^^^^^
|
||||
|
@ -45,7 +45,7 @@ LL | a = a - (a - 1);
|
|||
| ~~~~~~~~~~~~~~~
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:11:5
|
||||
--> $DIR/assign_ops2.rs:15:5
|
||||
|
|
||||
LL | a *= a * 99;
|
||||
| ^^^^^^^^^^^
|
||||
|
@ -60,7 +60,7 @@ LL | a = a * a * 99;
|
|||
| ~~~~~~~~~~~~~~
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:12:5
|
||||
--> $DIR/assign_ops2.rs:17:5
|
||||
|
|
||||
LL | a *= 42 * a;
|
||||
| ^^^^^^^^^^^
|
||||
|
@ -75,7 +75,7 @@ LL | a = a * 42 * a;
|
|||
| ~~~~~~~~~~~~~~
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:13:5
|
||||
--> $DIR/assign_ops2.rs:19:5
|
||||
|
|
||||
LL | a /= a / 2;
|
||||
| ^^^^^^^^^^
|
||||
|
@ -90,7 +90,7 @@ LL | a = a / (a / 2);
|
|||
| ~~~~~~~~~~~~~~~
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:14:5
|
||||
--> $DIR/assign_ops2.rs:21:5
|
||||
|
|
||||
LL | a %= a % 5;
|
||||
| ^^^^^^^^^^
|
||||
|
@ -105,7 +105,7 @@ LL | a = a % (a % 5);
|
|||
| ~~~~~~~~~~~~~~~
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:15:5
|
||||
--> $DIR/assign_ops2.rs:23:5
|
||||
|
|
||||
LL | a &= a & 1;
|
||||
| ^^^^^^^^^^
|
||||
|
@ -120,7 +120,7 @@ LL | a = a & a & 1;
|
|||
| ~~~~~~~~~~~~~
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:16:5
|
||||
--> $DIR/assign_ops2.rs:25:5
|
||||
|
|
||||
LL | a *= a * a;
|
||||
| ^^^^^^^^^^
|
||||
|
@ -135,7 +135,7 @@ LL | a = a * a * a;
|
|||
| ~~~~~~~~~~~~~
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops2.rs:53:5
|
||||
--> $DIR/assign_ops2.rs:63:5
|
||||
|
|
||||
LL | buf = buf + cows.clone();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()`
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#![allow(clippy::missing_docs_in_private_items, clippy::panic, clippy::unreachable)]
|
||||
|
||||
#[inline(always)]
|
||||
//~^ ERROR: you have declared `#[inline(always)]` on `test_attr_lint`. This is usually a b
|
||||
//~| NOTE: `-D clippy::inline-always` implied by `-D warnings`
|
||||
fn test_attr_lint() {
|
||||
assert!(true)
|
||||
}
|
||||
|
@ -23,9 +25,12 @@ fn empty_and_false_positive_stmt() {
|
|||
}
|
||||
|
||||
#[deprecated(since = "forever")]
|
||||
//~^ ERROR: the since field must contain a semver-compliant version
|
||||
//~| NOTE: `-D clippy::deprecated-semver` implied by `-D warnings`
|
||||
pub const SOME_CONST: u8 = 42;
|
||||
|
||||
#[deprecated(since = "1")]
|
||||
//~^ ERROR: the since field must contain a semver-compliant version
|
||||
pub const ANOTHER_CONST: u8 = 23;
|
||||
|
||||
#[deprecated(since = "0.1.1")]
|
||||
|
|
|
@ -7,7 +7,7 @@ LL | #[inline(always)]
|
|||
= note: `-D clippy::inline-always` implied by `-D warnings`
|
||||
|
||||
error: the since field must contain a semver-compliant version
|
||||
--> $DIR/attrs.rs:25:14
|
||||
--> $DIR/attrs.rs:27:14
|
||||
|
|
||||
LL | #[deprecated(since = "forever")]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
@ -15,7 +15,7 @@ LL | #[deprecated(since = "forever")]
|
|||
= note: `-D clippy::deprecated-semver` implied by `-D warnings`
|
||||
|
||||
error: the since field must contain a semver-compliant version
|
||||
--> $DIR/attrs.rs:28:14
|
||||
--> $DIR/attrs.rs:32:14
|
||||
|
|
||||
LL | #[deprecated(since = "1")]
|
||||
| ^^^^^^^^^^^
|
||||
|
|
|
@ -7,6 +7,7 @@ mod std_mutex {
|
|||
|
||||
pub async fn bad(x: &Mutex<u32>) -> u32 {
|
||||
let guard = x.lock().unwrap();
|
||||
//~^ ERROR: this `MutexGuard` is held across an `await` point
|
||||
baz().await
|
||||
}
|
||||
|
||||
|
@ -22,11 +23,13 @@ mod std_mutex {
|
|||
|
||||
pub async fn bad_rw(x: &RwLock<u32>) -> u32 {
|
||||
let guard = x.read().unwrap();
|
||||
//~^ ERROR: this `MutexGuard` is held across an `await` point
|
||||
baz().await
|
||||
}
|
||||
|
||||
pub async fn bad_rw_write(x: &RwLock<u32>) -> u32 {
|
||||
let mut guard = x.write().unwrap();
|
||||
//~^ ERROR: this `MutexGuard` is held across an `await` point
|
||||
baz().await
|
||||
}
|
||||
|
||||
|
@ -48,6 +51,7 @@ mod std_mutex {
|
|||
let first = baz().await;
|
||||
|
||||
let guard = x.lock().unwrap();
|
||||
//~^ ERROR: this `MutexGuard` is held across an `await` point
|
||||
|
||||
let second = baz().await;
|
||||
|
||||
|
@ -61,6 +65,7 @@ mod std_mutex {
|
|||
|
||||
let second = {
|
||||
let guard = x.lock().unwrap();
|
||||
//~^ ERROR: this `MutexGuard` is held across an `await` point
|
||||
baz().await
|
||||
};
|
||||
|
||||
|
@ -73,6 +78,7 @@ mod std_mutex {
|
|||
pub fn block_bad(x: &Mutex<u32>) -> impl std::future::Future<Output = u32> + '_ {
|
||||
async move {
|
||||
let guard = x.lock().unwrap();
|
||||
//~^ ERROR: this `MutexGuard` is held across an `await` point
|
||||
baz().await
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +91,7 @@ mod parking_lot_mutex {
|
|||
|
||||
pub async fn bad(x: &Mutex<u32>) -> u32 {
|
||||
let guard = x.lock();
|
||||
//~^ ERROR: this `MutexGuard` is held across an `await` point
|
||||
baz().await
|
||||
}
|
||||
|
||||
|
@ -100,11 +107,13 @@ mod parking_lot_mutex {
|
|||
|
||||
pub async fn bad_rw(x: &RwLock<u32>) -> u32 {
|
||||
let guard = x.read();
|
||||
//~^ ERROR: this `MutexGuard` is held across an `await` point
|
||||
baz().await
|
||||
}
|
||||
|
||||
pub async fn bad_rw_write(x: &RwLock<u32>) -> u32 {
|
||||
let mut guard = x.write();
|
||||
//~^ ERROR: this `MutexGuard` is held across an `await` point
|
||||
baz().await
|
||||
}
|
||||
|
||||
|
@ -126,6 +135,7 @@ mod parking_lot_mutex {
|
|||
let first = baz().await;
|
||||
|
||||
let guard = x.lock();
|
||||
//~^ ERROR: this `MutexGuard` is held across an `await` point
|
||||
|
||||
let second = baz().await;
|
||||
|
||||
|
@ -139,6 +149,7 @@ mod parking_lot_mutex {
|
|||
|
||||
let second = {
|
||||
let guard = x.lock();
|
||||
//~^ ERROR: this `MutexGuard` is held across an `await` point
|
||||
baz().await
|
||||
};
|
||||
|
||||
|
@ -151,6 +162,7 @@ mod parking_lot_mutex {
|
|||
pub fn block_bad(x: &Mutex<u32>) -> impl std::future::Future<Output = u32> + '_ {
|
||||
async move {
|
||||
let guard = x.lock();
|
||||
//~^ ERROR: this `MutexGuard` is held across an `await` point
|
||||
baz().await
|
||||
}
|
||||
}
|
||||
|
@ -171,6 +183,7 @@ async fn no_await(x: std::sync::Mutex<u32>) {
|
|||
// `*guard += 1` is removed it is picked up.
|
||||
async fn dropped_before_await(x: std::sync::Mutex<u32>) {
|
||||
let mut guard = x.lock().unwrap();
|
||||
//~^ ERROR: this `MutexGuard` is held across an `await` point
|
||||
*guard += 1;
|
||||
drop(guard);
|
||||
baz().await;
|
||||
|
|
|
@ -9,195 +9,206 @@ note: these are all the `await` points this lock is held through
|
|||
--> $DIR/await_holding_lock.rs:9:9
|
||||
|
|
||||
LL | / let guard = x.lock().unwrap();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | }
|
||||
| |_____^
|
||||
= note: `-D clippy::await-holding-lock` implied by `-D warnings`
|
||||
|
||||
error: this `MutexGuard` is held across an `await` point
|
||||
--> $DIR/await_holding_lock.rs:24:13
|
||||
--> $DIR/await_holding_lock.rs:25:13
|
||||
|
|
||||
LL | let guard = x.read().unwrap();
|
||||
| ^^^^^
|
||||
|
|
||||
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
|
||||
note: these are all the `await` points this lock is held through
|
||||
--> $DIR/await_holding_lock.rs:24:9
|
||||
--> $DIR/await_holding_lock.rs:25:9
|
||||
|
|
||||
LL | / let guard = x.read().unwrap();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: this `MutexGuard` is held across an `await` point
|
||||
--> $DIR/await_holding_lock.rs:29:13
|
||||
--> $DIR/await_holding_lock.rs:31:13
|
||||
|
|
||||
LL | let mut guard = x.write().unwrap();
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
|
||||
note: these are all the `await` points this lock is held through
|
||||
--> $DIR/await_holding_lock.rs:29:9
|
||||
--> $DIR/await_holding_lock.rs:31:9
|
||||
|
|
||||
LL | / let mut guard = x.write().unwrap();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: this `MutexGuard` is held across an `await` point
|
||||
--> $DIR/await_holding_lock.rs:50:13
|
||||
--> $DIR/await_holding_lock.rs:53:13
|
||||
|
|
||||
LL | let guard = x.lock().unwrap();
|
||||
| ^^^^^
|
||||
|
|
||||
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
|
||||
note: these are all the `await` points this lock is held through
|
||||
--> $DIR/await_holding_lock.rs:50:9
|
||||
--> $DIR/await_holding_lock.rs:53:9
|
||||
|
|
||||
LL | / let guard = x.lock().unwrap();
|
||||
LL | |
|
||||
LL | | let second = baz().await;
|
||||
LL | |
|
||||
LL | | let second = baz().await;
|
||||
... |
|
||||
LL | | first + second + third
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: this `MutexGuard` is held across an `await` point
|
||||
--> $DIR/await_holding_lock.rs:63:17
|
||||
--> $DIR/await_holding_lock.rs:67:17
|
||||
|
|
||||
LL | let guard = x.lock().unwrap();
|
||||
| ^^^^^
|
||||
|
|
||||
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
|
||||
note: these are all the `await` points this lock is held through
|
||||
--> $DIR/await_holding_lock.rs:63:13
|
||||
--> $DIR/await_holding_lock.rs:67:13
|
||||
|
|
||||
LL | / let guard = x.lock().unwrap();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | };
|
||||
| |_________^
|
||||
|
||||
error: this `MutexGuard` is held across an `await` point
|
||||
--> $DIR/await_holding_lock.rs:75:17
|
||||
--> $DIR/await_holding_lock.rs:80:17
|
||||
|
|
||||
LL | let guard = x.lock().unwrap();
|
||||
| ^^^^^
|
||||
|
|
||||
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
|
||||
note: these are all the `await` points this lock is held through
|
||||
--> $DIR/await_holding_lock.rs:75:13
|
||||
--> $DIR/await_holding_lock.rs:80:13
|
||||
|
|
||||
LL | / let guard = x.lock().unwrap();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | }
|
||||
| |_________^
|
||||
|
||||
error: this `MutexGuard` is held across an `await` point
|
||||
--> $DIR/await_holding_lock.rs:87:13
|
||||
--> $DIR/await_holding_lock.rs:93:13
|
||||
|
|
||||
LL | let guard = x.lock();
|
||||
| ^^^^^
|
||||
|
|
||||
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
|
||||
note: these are all the `await` points this lock is held through
|
||||
--> $DIR/await_holding_lock.rs:87:9
|
||||
--> $DIR/await_holding_lock.rs:93:9
|
||||
|
|
||||
LL | / let guard = x.lock();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: this `MutexGuard` is held across an `await` point
|
||||
--> $DIR/await_holding_lock.rs:102:13
|
||||
--> $DIR/await_holding_lock.rs:109:13
|
||||
|
|
||||
LL | let guard = x.read();
|
||||
| ^^^^^
|
||||
|
|
||||
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
|
||||
note: these are all the `await` points this lock is held through
|
||||
--> $DIR/await_holding_lock.rs:102:9
|
||||
--> $DIR/await_holding_lock.rs:109:9
|
||||
|
|
||||
LL | / let guard = x.read();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: this `MutexGuard` is held across an `await` point
|
||||
--> $DIR/await_holding_lock.rs:107:13
|
||||
--> $DIR/await_holding_lock.rs:115:13
|
||||
|
|
||||
LL | let mut guard = x.write();
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
|
||||
note: these are all the `await` points this lock is held through
|
||||
--> $DIR/await_holding_lock.rs:107:9
|
||||
--> $DIR/await_holding_lock.rs:115:9
|
||||
|
|
||||
LL | / let mut guard = x.write();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: this `MutexGuard` is held across an `await` point
|
||||
--> $DIR/await_holding_lock.rs:128:13
|
||||
--> $DIR/await_holding_lock.rs:137:13
|
||||
|
|
||||
LL | let guard = x.lock();
|
||||
| ^^^^^
|
||||
|
|
||||
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
|
||||
note: these are all the `await` points this lock is held through
|
||||
--> $DIR/await_holding_lock.rs:128:9
|
||||
--> $DIR/await_holding_lock.rs:137:9
|
||||
|
|
||||
LL | / let guard = x.lock();
|
||||
LL | |
|
||||
LL | | let second = baz().await;
|
||||
LL | |
|
||||
LL | | let second = baz().await;
|
||||
... |
|
||||
LL | | first + second + third
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: this `MutexGuard` is held across an `await` point
|
||||
--> $DIR/await_holding_lock.rs:141:17
|
||||
--> $DIR/await_holding_lock.rs:151:17
|
||||
|
|
||||
LL | let guard = x.lock();
|
||||
| ^^^^^
|
||||
|
|
||||
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
|
||||
note: these are all the `await` points this lock is held through
|
||||
--> $DIR/await_holding_lock.rs:141:13
|
||||
--> $DIR/await_holding_lock.rs:151:13
|
||||
|
|
||||
LL | / let guard = x.lock();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | };
|
||||
| |_________^
|
||||
|
||||
error: this `MutexGuard` is held across an `await` point
|
||||
--> $DIR/await_holding_lock.rs:153:17
|
||||
--> $DIR/await_holding_lock.rs:164:17
|
||||
|
|
||||
LL | let guard = x.lock();
|
||||
| ^^^^^
|
||||
|
|
||||
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
|
||||
note: these are all the `await` points this lock is held through
|
||||
--> $DIR/await_holding_lock.rs:153:13
|
||||
--> $DIR/await_holding_lock.rs:164:13
|
||||
|
|
||||
LL | / let guard = x.lock();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | }
|
||||
| |_________^
|
||||
|
||||
error: this `MutexGuard` is held across an `await` point
|
||||
--> $DIR/await_holding_lock.rs:173:9
|
||||
--> $DIR/await_holding_lock.rs:185:9
|
||||
|
|
||||
LL | let mut guard = x.lock().unwrap();
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
|
||||
note: these are all the `await` points this lock is held through
|
||||
--> $DIR/await_holding_lock.rs:173:5
|
||||
--> $DIR/await_holding_lock.rs:185:5
|
||||
|
|
||||
LL | / let mut guard = x.lock().unwrap();
|
||||
LL | |
|
||||
LL | | *guard += 1;
|
||||
LL | | drop(guard);
|
||||
LL | | baz().await;
|
||||
|
|
|
@ -4,11 +4,13 @@ use std::cell::RefCell;
|
|||
|
||||
async fn bad(x: &RefCell<u32>) -> u32 {
|
||||
let b = x.borrow();
|
||||
//~^ ERROR: this `RefCell` reference is held across an `await` point
|
||||
baz().await
|
||||
}
|
||||
|
||||
async fn bad_mut(x: &RefCell<u32>) -> u32 {
|
||||
let b = x.borrow_mut();
|
||||
//~^ ERROR: this `RefCell` reference is held across an `await` point
|
||||
baz().await
|
||||
}
|
||||
|
||||
|
@ -30,6 +32,7 @@ async fn also_bad(x: &RefCell<u32>) -> u32 {
|
|||
let first = baz().await;
|
||||
|
||||
let b = x.borrow_mut();
|
||||
//~^ ERROR: this `RefCell` reference is held across an `await` point
|
||||
|
||||
let second = baz().await;
|
||||
|
||||
|
@ -42,6 +45,7 @@ async fn less_bad(x: &RefCell<u32>) -> u32 {
|
|||
let first = baz().await;
|
||||
|
||||
let b = x.borrow_mut();
|
||||
//~^ ERROR: this `RefCell` reference is held across an `await` point
|
||||
|
||||
let second = baz().await;
|
||||
|
||||
|
@ -57,6 +61,7 @@ async fn not_good(x: &RefCell<u32>) -> u32 {
|
|||
|
||||
let second = {
|
||||
let b = x.borrow_mut();
|
||||
//~^ ERROR: this `RefCell` reference is held across an `await` point
|
||||
baz().await
|
||||
};
|
||||
|
||||
|
@ -69,6 +74,7 @@ async fn not_good(x: &RefCell<u32>) -> u32 {
|
|||
fn block_bad(x: &RefCell<u32>) -> impl std::future::Future<Output = u32> + '_ {
|
||||
async move {
|
||||
let b = x.borrow_mut();
|
||||
//~^ ERROR: this `RefCell` reference is held across an `await` point
|
||||
baz().await
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,90 +9,94 @@ note: these are all the `await` points this reference is held through
|
|||
--> $DIR/await_holding_refcell_ref.rs:6:5
|
||||
|
|
||||
LL | / let b = x.borrow();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | }
|
||||
| |_^
|
||||
= note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings`
|
||||
|
||||
error: this `RefCell` reference is held across an `await` point
|
||||
--> $DIR/await_holding_refcell_ref.rs:11:9
|
||||
--> $DIR/await_holding_refcell_ref.rs:12:9
|
||||
|
|
||||
LL | let b = x.borrow_mut();
|
||||
| ^
|
||||
|
|
||||
= help: ensure the reference is dropped before calling `await`
|
||||
note: these are all the `await` points this reference is held through
|
||||
--> $DIR/await_holding_refcell_ref.rs:11:5
|
||||
--> $DIR/await_holding_refcell_ref.rs:12:5
|
||||
|
|
||||
LL | / let b = x.borrow_mut();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: this `RefCell` reference is held across an `await` point
|
||||
--> $DIR/await_holding_refcell_ref.rs:32:9
|
||||
--> $DIR/await_holding_refcell_ref.rs:34:9
|
||||
|
|
||||
LL | let b = x.borrow_mut();
|
||||
| ^
|
||||
|
|
||||
= help: ensure the reference is dropped before calling `await`
|
||||
note: these are all the `await` points this reference is held through
|
||||
--> $DIR/await_holding_refcell_ref.rs:32:5
|
||||
--> $DIR/await_holding_refcell_ref.rs:34:5
|
||||
|
|
||||
LL | / let b = x.borrow_mut();
|
||||
LL | |
|
||||
LL | | let second = baz().await;
|
||||
LL | |
|
||||
LL | | let second = baz().await;
|
||||
... |
|
||||
LL | | first + second + third
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: this `RefCell` reference is held across an `await` point
|
||||
--> $DIR/await_holding_refcell_ref.rs:44:9
|
||||
--> $DIR/await_holding_refcell_ref.rs:47:9
|
||||
|
|
||||
LL | let b = x.borrow_mut();
|
||||
| ^
|
||||
|
|
||||
= help: ensure the reference is dropped before calling `await`
|
||||
note: these are all the `await` points this reference is held through
|
||||
--> $DIR/await_holding_refcell_ref.rs:44:5
|
||||
--> $DIR/await_holding_refcell_ref.rs:47:5
|
||||
|
|
||||
LL | / let b = x.borrow_mut();
|
||||
LL | |
|
||||
LL | | let second = baz().await;
|
||||
LL | |
|
||||
LL | | let second = baz().await;
|
||||
... |
|
||||
LL | | first + second + third
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: this `RefCell` reference is held across an `await` point
|
||||
--> $DIR/await_holding_refcell_ref.rs:59:13
|
||||
--> $DIR/await_holding_refcell_ref.rs:63:13
|
||||
|
|
||||
LL | let b = x.borrow_mut();
|
||||
| ^
|
||||
|
|
||||
= help: ensure the reference is dropped before calling `await`
|
||||
note: these are all the `await` points this reference is held through
|
||||
--> $DIR/await_holding_refcell_ref.rs:59:9
|
||||
--> $DIR/await_holding_refcell_ref.rs:63:9
|
||||
|
|
||||
LL | / let b = x.borrow_mut();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | };
|
||||
| |_____^
|
||||
|
||||
error: this `RefCell` reference is held across an `await` point
|
||||
--> $DIR/await_holding_refcell_ref.rs:71:13
|
||||
--> $DIR/await_holding_refcell_ref.rs:76:13
|
||||
|
|
||||
LL | let b = x.borrow_mut();
|
||||
| ^
|
||||
|
|
||||
= help: ensure the reference is dropped before calling `await`
|
||||
note: these are all the `await` points this reference is held through
|
||||
--> $DIR/await_holding_refcell_ref.rs:71:9
|
||||
--> $DIR/await_holding_refcell_ref.rs:76:9
|
||||
|
|
||||
LL | / let b = x.borrow_mut();
|
||||
LL | |
|
||||
LL | | baz().await
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
|
@ -12,19 +12,27 @@ fn main() {
|
|||
let x = 5;
|
||||
|
||||
x & 0 == 0;
|
||||
//~^ ERROR: &-masking with zero
|
||||
//~| NOTE: `-D clippy::bad-bit-mask` implied by `-D warnings`
|
||||
//~| ERROR: this operation will always return zero. This is likely not the intended ou
|
||||
//~| NOTE: `#[deny(clippy::erasing_op)]` on by default
|
||||
x & 1 == 1; //ok, distinguishes bit 0
|
||||
x & 1 == 0; //ok, compared with zero
|
||||
x & 2 == 1;
|
||||
//~^ ERROR: incompatible bit mask: `_ & 2` can never be equal to `1`
|
||||
x | 0 == 0; //ok, equals x == 0 (maybe warn?)
|
||||
x | 1 == 3; //ok, equals x == 2 || x == 3
|
||||
x | 3 == 3; //ok, equals x <= 3
|
||||
x | 3 == 2;
|
||||
//~^ ERROR: incompatible bit mask: `_ | 3` can never be equal to `2`
|
||||
|
||||
x & 1 > 1;
|
||||
//~^ ERROR: incompatible bit mask: `_ & 1` will never be higher than `1`
|
||||
x & 2 > 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0
|
||||
x & 2 < 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0
|
||||
x | 1 > 1; // ok (if a bit silly), equals x > 1
|
||||
x | 2 > 1;
|
||||
//~^ ERROR: incompatible bit mask: `_ | 2` will always be higher than `1`
|
||||
x | 2 <= 2; // ok (if a bit silly), equals x <= 2
|
||||
|
||||
x & 192 == 128; // ok, tests for bit 7 and not bit 6
|
||||
|
@ -32,15 +40,22 @@ fn main() {
|
|||
|
||||
// this also now works with constants
|
||||
x & THREE_BITS == 8;
|
||||
//~^ ERROR: incompatible bit mask: `_ & 7` can never be equal to `8`
|
||||
x | EVEN_MORE_REDIRECTION < 7;
|
||||
//~^ ERROR: incompatible bit mask: `_ | 7` will never be lower than `7`
|
||||
|
||||
0 & x == 0;
|
||||
//~^ ERROR: &-masking with zero
|
||||
//~| ERROR: this operation will always return zero. This is likely not the intended ou
|
||||
1 | x > 1;
|
||||
|
||||
// and should now also match uncommon usage
|
||||
1 < 2 | x;
|
||||
//~^ ERROR: incompatible bit mask: `_ | 2` will always be higher than `1`
|
||||
2 == 3 | x;
|
||||
//~^ ERROR: incompatible bit mask: `_ | 3` can never be equal to `2`
|
||||
1 == x & 2;
|
||||
//~^ ERROR: incompatible bit mask: `_ & 2` can never be equal to `1`
|
||||
|
||||
x | 1 > 2; // no error, because we allowed ineffective bit masks
|
||||
ineffective();
|
||||
|
@ -52,9 +67,14 @@ fn ineffective() {
|
|||
let x = 5;
|
||||
|
||||
x | 1 > 3;
|
||||
//~^ ERROR: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared d
|
||||
//~| NOTE: `-D clippy::ineffective-bit-mask` implied by `-D warnings`
|
||||
x | 1 < 4;
|
||||
//~^ ERROR: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared d
|
||||
x | 1 <= 3;
|
||||
//~^ ERROR: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared d
|
||||
x | 1 >= 8;
|
||||
//~^ ERROR: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared d
|
||||
|
||||
x | 1 > 2; // not an error (yet), better written as x >= 2
|
||||
x | 1 >= 7; // not an error (yet), better written as x >= 6
|
||||
|
|
|
@ -15,73 +15,73 @@ LL | x & 0 == 0;
|
|||
= note: `#[deny(clippy::erasing_op)]` on by default
|
||||
|
||||
error: incompatible bit mask: `_ & 2` can never be equal to `1`
|
||||
--> $DIR/bit_masks.rs:17:5
|
||||
--> $DIR/bit_masks.rs:21:5
|
||||
|
|
||||
LL | x & 2 == 1;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ | 3` can never be equal to `2`
|
||||
--> $DIR/bit_masks.rs:21:5
|
||||
--> $DIR/bit_masks.rs:26:5
|
||||
|
|
||||
LL | x | 3 == 2;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ & 1` will never be higher than `1`
|
||||
--> $DIR/bit_masks.rs:23:5
|
||||
--> $DIR/bit_masks.rs:29:5
|
||||
|
|
||||
LL | x & 1 > 1;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ | 2` will always be higher than `1`
|
||||
--> $DIR/bit_masks.rs:27:5
|
||||
--> $DIR/bit_masks.rs:34:5
|
||||
|
|
||||
LL | x | 2 > 1;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ & 7` can never be equal to `8`
|
||||
--> $DIR/bit_masks.rs:34:5
|
||||
--> $DIR/bit_masks.rs:42:5
|
||||
|
|
||||
LL | x & THREE_BITS == 8;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ | 7` will never be lower than `7`
|
||||
--> $DIR/bit_masks.rs:35:5
|
||||
--> $DIR/bit_masks.rs:44:5
|
||||
|
|
||||
LL | x | EVEN_MORE_REDIRECTION < 7;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: &-masking with zero
|
||||
--> $DIR/bit_masks.rs:37:5
|
||||
--> $DIR/bit_masks.rs:47:5
|
||||
|
|
||||
LL | 0 & x == 0;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: this operation will always return zero. This is likely not the intended outcome
|
||||
--> $DIR/bit_masks.rs:37:5
|
||||
--> $DIR/bit_masks.rs:47:5
|
||||
|
|
||||
LL | 0 & x == 0;
|
||||
| ^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ | 2` will always be higher than `1`
|
||||
--> $DIR/bit_masks.rs:41:5
|
||||
--> $DIR/bit_masks.rs:53:5
|
||||
|
|
||||
LL | 1 < 2 | x;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ | 3` can never be equal to `2`
|
||||
--> $DIR/bit_masks.rs:42:5
|
||||
--> $DIR/bit_masks.rs:55:5
|
||||
|
|
||||
LL | 2 == 3 | x;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ & 2` can never be equal to `1`
|
||||
--> $DIR/bit_masks.rs:43:5
|
||||
--> $DIR/bit_masks.rs:57:5
|
||||
|
|
||||
LL | 1 == x & 2;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly
|
||||
--> $DIR/bit_masks.rs:54:5
|
||||
--> $DIR/bit_masks.rs:69:5
|
||||
|
|
||||
LL | x | 1 > 3;
|
||||
| ^^^^^^^^^
|
||||
|
@ -89,19 +89,19 @@ LL | x | 1 > 3;
|
|||
= note: `-D clippy::ineffective-bit-mask` implied by `-D warnings`
|
||||
|
||||
error: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared directly
|
||||
--> $DIR/bit_masks.rs:55:5
|
||||
--> $DIR/bit_masks.rs:72:5
|
||||
|
|
||||
LL | x | 1 < 4;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly
|
||||
--> $DIR/bit_masks.rs:56:5
|
||||
--> $DIR/bit_masks.rs:74:5
|
||||
|
|
||||
LL | x | 1 <= 3;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared directly
|
||||
--> $DIR/bit_masks.rs:57:5
|
||||
--> $DIR/bit_masks.rs:76:5
|
||||
|
|
||||
LL | x | 1 >= 8;
|
||||
| ^^^^^^^^^^
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
|
||||
//! Test that the whole restriction group is not enabled
|
||||
#![warn(clippy::restriction)]
|
||||
//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group
|
||||
#![deny(clippy::restriction)]
|
||||
//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group
|
||||
#![forbid(clippy::restriction)]
|
||||
//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -13,7 +13,7 @@ LL | #![warn(clippy::restriction)]
|
|||
= help: enable the restriction lints you need individually
|
||||
|
||||
error: `clippy::restriction` is not meant to be enabled as a group
|
||||
--> $DIR/blanket_clippy_restriction_lints.rs:7:9
|
||||
--> $DIR/blanket_clippy_restriction_lints.rs:8:9
|
||||
|
|
||||
LL | #![deny(clippy::restriction)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -21,7 +21,7 @@ LL | #![deny(clippy::restriction)]
|
|||
= help: enable the restriction lints you need individually
|
||||
|
||||
error: `clippy::restriction` is not meant to be enabled as a group
|
||||
--> $DIR/blanket_clippy_restriction_lints.rs:8:11
|
||||
--> $DIR/blanket_clippy_restriction_lints.rs:10:11
|
||||
|
|
||||
LL | #![forbid(clippy::restriction)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -21,6 +21,8 @@ fn pred_test() {
|
|||
&& sky == "blue"
|
||||
&& predicate(
|
||||
|x| {
|
||||
//~^ ERROR: in an `if` condition, avoid complex blocks or closures with blocks
|
||||
//~| NOTE: `-D clippy::blocks-in-if-conditions` implied by `-D warnings`
|
||||
let target = 3;
|
||||
x == target
|
||||
},
|
||||
|
@ -30,6 +32,7 @@ fn pred_test() {
|
|||
|
||||
if predicate(
|
||||
|x| {
|
||||
//~^ ERROR: in an `if` condition, avoid complex blocks or closures with blocks; in
|
||||
let target = 3;
|
||||
x == target
|
||||
},
|
||||
|
|
|
@ -3,6 +3,8 @@ error: in an `if` condition, avoid complex blocks or closures with blocks; inste
|
|||
|
|
||||
LL | |x| {
|
||||
| _________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | let target = 3;
|
||||
LL | | x == target
|
||||
LL | | },
|
||||
|
@ -11,10 +13,11 @@ LL | | },
|
|||
= note: `-D clippy::blocks-in-if-conditions` implied by `-D warnings`
|
||||
|
||||
error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
|
||||
--> $DIR/blocks_in_if_conditions_closure.rs:32:13
|
||||
--> $DIR/blocks_in_if_conditions_closure.rs:34:13
|
||||
|
|
||||
LL | |x| {
|
||||
| _____________^
|
||||
LL | |
|
||||
LL | | let target = 3;
|
||||
LL | | x == target
|
||||
LL | | },
|
||||
|
|
|
@ -23,14 +23,17 @@ pub fn test1(foo: &mut Box<bool>) {
|
|||
|
||||
pub fn test2() {
|
||||
let foo: &Box<bool>;
|
||||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
}
|
||||
|
||||
struct Test3<'a> {
|
||||
foo: &'a Box<bool>,
|
||||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
}
|
||||
|
||||
trait Test4 {
|
||||
fn test4(a: &Box<bool>);
|
||||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
}
|
||||
|
||||
impl<'a> Test4 for Test3<'a> {
|
||||
|
@ -97,17 +100,24 @@ pub fn test13(boxed_slice: &mut Box<[i32]>) {
|
|||
|
||||
// The suggestion should include proper parentheses to avoid a syntax error.
|
||||
pub fn test14(_display: &Box<dyn Display>) {}
|
||||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
pub fn test15(_display: &Box<dyn Display + Send>) {}
|
||||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
pub fn test16<'a>(_display: &'a Box<dyn Display + 'a>) {}
|
||||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
|
||||
pub fn test17(_display: &Box<impl Display>) {}
|
||||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
pub fn test18(_display: &Box<impl Display + Send>) {}
|
||||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {}
|
||||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
|
||||
// This exists only to check what happens when parentheses are already present.
|
||||
// Even though the current implementation doesn't put extra parentheses,
|
||||
// it's fine that unnecessary parentheses appear in the future for some reason.
|
||||
pub fn test20(_display: &Box<(dyn Display + Send)>) {}
|
||||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
|
||||
fn main() {
|
||||
test1(&mut Box::new(false));
|
||||
|
|
|
@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)]
|
|||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
--> $DIR/borrow_box.rs:29:10
|
||||
--> $DIR/borrow_box.rs:30:10
|
||||
|
|
||||
LL | foo: &'a Box<bool>,
|
||||
| ^^^^^^^^^^^^^ help: try: `&'a bool`
|
||||
|
||||
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
--> $DIR/borrow_box.rs:33:17
|
||||
--> $DIR/borrow_box.rs:35:17
|
||||
|
|
||||
LL | fn test4(a: &Box<bool>);
|
||||
| ^^^^^^^^^^ help: try: `&bool`
|
||||
|
||||
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
--> $DIR/borrow_box.rs:99:25
|
||||
--> $DIR/borrow_box.rs:102:25
|
||||
|
|
||||
LL | pub fn test14(_display: &Box<dyn Display>) {}
|
||||
| ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display`
|
||||
|
||||
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
--> $DIR/borrow_box.rs:100:25
|
||||
--> $DIR/borrow_box.rs:104:25
|
||||
|
|
||||
LL | pub fn test15(_display: &Box<dyn Display + Send>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`
|
||||
|
||||
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
--> $DIR/borrow_box.rs:101:29
|
||||
--> $DIR/borrow_box.rs:106:29
|
||||
|
|
||||
LL | pub fn test16<'a>(_display: &'a Box<dyn Display + 'a>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)`
|
||||
|
||||
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
--> $DIR/borrow_box.rs:103:25
|
||||
--> $DIR/borrow_box.rs:109:25
|
||||
|
|
||||
LL | pub fn test17(_display: &Box<impl Display>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display`
|
||||
|
||||
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
--> $DIR/borrow_box.rs:104:25
|
||||
--> $DIR/borrow_box.rs:111:25
|
||||
|
|
||||
LL | pub fn test18(_display: &Box<impl Display + Send>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)`
|
||||
|
||||
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
--> $DIR/borrow_box.rs:105:29
|
||||
--> $DIR/borrow_box.rs:113:29
|
||||
|
|
||||
LL | pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)`
|
||||
|
||||
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
--> $DIR/borrow_box.rs:110:25
|
||||
--> $DIR/borrow_box.rs:119:25
|
||||
|
|
||||
LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`
|
||||
|
|
|
@ -7,5 +7,7 @@ mod should_lint {
|
|||
fn two_helps() {
|
||||
let s = &String::new();
|
||||
let x: &str = &*s;
|
||||
//~^ ERROR: deref on an immutable reference
|
||||
//~| NOTE: `-D clippy::borrow-deref-ref` implied by `-D warnings`
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ fn test_macro() {
|
|||
}
|
||||
|
||||
fn test1(foo: Box<Vec<bool>>) {}
|
||||
//~^ ERROR: you seem to be trying to use `Box<Vec<..>>`. Consider using just `Vec<..>`
|
||||
|
||||
fn test2(foo: Box<dyn Fn(Vec<u32>)>) {
|
||||
// pass if #31 is fixed
|
||||
|
@ -26,20 +27,28 @@ fn test2(foo: Box<dyn Fn(Vec<u32>)>) {
|
|||
}
|
||||
|
||||
fn test3(foo: Box<String>) {}
|
||||
//~^ ERROR: you seem to be trying to use `Box<String>`. Consider using just `String`
|
||||
|
||||
fn test4(foo: Box<HashMap<String, String>>) {}
|
||||
//~^ ERROR: you seem to be trying to use `Box<HashMap<..>>`. Consider using just `HashMap<
|
||||
|
||||
fn test5(foo: Box<HashSet<i64>>) {}
|
||||
//~^ ERROR: you seem to be trying to use `Box<HashSet<..>>`. Consider using just `HashSet<
|
||||
|
||||
fn test6(foo: Box<VecDeque<i32>>) {}
|
||||
//~^ ERROR: you seem to be trying to use `Box<VecDeque<..>>`. Consider using just `VecDequ
|
||||
|
||||
fn test7(foo: Box<LinkedList<i16>>) {}
|
||||
//~^ ERROR: you seem to be trying to use `Box<LinkedList<..>>`. Consider using just `Linke
|
||||
|
||||
fn test8(foo: Box<BTreeMap<i8, String>>) {}
|
||||
//~^ ERROR: you seem to be trying to use `Box<BTreeMap<..>>`. Consider using just `BTreeMa
|
||||
|
||||
fn test9(foo: Box<BTreeSet<u64>>) {}
|
||||
//~^ ERROR: you seem to be trying to use `Box<BTreeSet<..>>`. Consider using just `BTreeSe
|
||||
|
||||
fn test10(foo: Box<BinaryHeap<u32>>) {}
|
||||
//~^ ERROR: you seem to be trying to use `Box<BinaryHeap<..>>`. Consider using just `Binar
|
||||
|
||||
fn test_local_not_linted() {
|
||||
let _: Box<Vec<bool>>;
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | fn test1(foo: Box<Vec<bool>>) {}
|
|||
= note: `-D clippy::box-collection` implied by `-D warnings`
|
||||
|
||||
error: you seem to be trying to use `Box<String>`. Consider using just `String`
|
||||
--> $DIR/box_collection.rs:28:15
|
||||
--> $DIR/box_collection.rs:29:15
|
||||
|
|
||||
LL | fn test3(foo: Box<String>) {}
|
||||
| ^^^^^^^^^^^
|
||||
|
@ -16,7 +16,7 @@ LL | fn test3(foo: Box<String>) {}
|
|||
= help: `String` is already on the heap, `Box<String>` makes an extra allocation
|
||||
|
||||
error: you seem to be trying to use `Box<HashMap<..>>`. Consider using just `HashMap<..>`
|
||||
--> $DIR/box_collection.rs:30:15
|
||||
--> $DIR/box_collection.rs:32:15
|
||||
|
|
||||
LL | fn test4(foo: Box<HashMap<String, String>>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -24,7 +24,7 @@ LL | fn test4(foo: Box<HashMap<String, String>>) {}
|
|||
= help: `HashMap<..>` is already on the heap, `Box<HashMap<..>>` makes an extra allocation
|
||||
|
||||
error: you seem to be trying to use `Box<HashSet<..>>`. Consider using just `HashSet<..>`
|
||||
--> $DIR/box_collection.rs:32:15
|
||||
--> $DIR/box_collection.rs:35:15
|
||||
|
|
||||
LL | fn test5(foo: Box<HashSet<i64>>) {}
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
@ -32,7 +32,7 @@ LL | fn test5(foo: Box<HashSet<i64>>) {}
|
|||
= help: `HashSet<..>` is already on the heap, `Box<HashSet<..>>` makes an extra allocation
|
||||
|
||||
error: you seem to be trying to use `Box<VecDeque<..>>`. Consider using just `VecDeque<..>`
|
||||
--> $DIR/box_collection.rs:34:15
|
||||
--> $DIR/box_collection.rs:38:15
|
||||
|
|
||||
LL | fn test6(foo: Box<VecDeque<i32>>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
@ -40,7 +40,7 @@ LL | fn test6(foo: Box<VecDeque<i32>>) {}
|
|||
= help: `VecDeque<..>` is already on the heap, `Box<VecDeque<..>>` makes an extra allocation
|
||||
|
||||
error: you seem to be trying to use `Box<LinkedList<..>>`. Consider using just `LinkedList<..>`
|
||||
--> $DIR/box_collection.rs:36:15
|
||||
--> $DIR/box_collection.rs:41:15
|
||||
|
|
||||
LL | fn test7(foo: Box<LinkedList<i16>>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -48,7 +48,7 @@ LL | fn test7(foo: Box<LinkedList<i16>>) {}
|
|||
= help: `LinkedList<..>` is already on the heap, `Box<LinkedList<..>>` makes an extra allocation
|
||||
|
||||
error: you seem to be trying to use `Box<BTreeMap<..>>`. Consider using just `BTreeMap<..>`
|
||||
--> $DIR/box_collection.rs:38:15
|
||||
--> $DIR/box_collection.rs:44:15
|
||||
|
|
||||
LL | fn test8(foo: Box<BTreeMap<i8, String>>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -56,7 +56,7 @@ LL | fn test8(foo: Box<BTreeMap<i8, String>>) {}
|
|||
= help: `BTreeMap<..>` is already on the heap, `Box<BTreeMap<..>>` makes an extra allocation
|
||||
|
||||
error: you seem to be trying to use `Box<BTreeSet<..>>`. Consider using just `BTreeSet<..>`
|
||||
--> $DIR/box_collection.rs:40:15
|
||||
--> $DIR/box_collection.rs:47:15
|
||||
|
|
||||
LL | fn test9(foo: Box<BTreeSet<u64>>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
@ -64,7 +64,7 @@ LL | fn test9(foo: Box<BTreeSet<u64>>) {}
|
|||
= help: `BTreeSet<..>` is already on the heap, `Box<BTreeSet<..>>` makes an extra allocation
|
||||
|
||||
error: you seem to be trying to use `Box<BinaryHeap<..>>`. Consider using just `BinaryHeap<..>`
|
||||
--> $DIR/box_collection.rs:42:16
|
||||
--> $DIR/box_collection.rs:50:16
|
||||
|
|
||||
LL | fn test10(foo: Box<BinaryHeap<u32>>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -38,6 +38,8 @@ fn warn_call() {
|
|||
}
|
||||
|
||||
fn warn_arg(x: Box<A>) {
|
||||
//~^ ERROR: local variable doesn't need to be boxed here
|
||||
//~| NOTE: `-D clippy::boxed-local` implied by `-D warnings`
|
||||
x.foo();
|
||||
}
|
||||
|
||||
|
@ -119,6 +121,7 @@ pub struct PeekableSeekable<I: Foo> {
|
|||
}
|
||||
|
||||
pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
|
||||
//~^ ERROR: local variable doesn't need to be boxed here
|
||||
|
||||
/// Regression for #916, #1123
|
||||
///
|
||||
|
@ -183,6 +186,7 @@ mod issue4804 {
|
|||
|
||||
// warn on `x: Box<u32>`
|
||||
fn default_impl_x(self: Box<Self>, x: Box<u32>) -> u32 {
|
||||
//~^ ERROR: local variable doesn't need to be boxed here
|
||||
4
|
||||
}
|
||||
}
|
||||
|
@ -190,6 +194,7 @@ mod issue4804 {
|
|||
trait WarnTrait {
|
||||
// warn on `x: Box<u32>`
|
||||
fn foo(x: Box<u32>) {}
|
||||
//~^ ERROR: local variable doesn't need to be boxed here
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,19 +7,19 @@ LL | fn warn_arg(x: Box<A>) {
|
|||
= note: `-D clippy::boxed-local` implied by `-D warnings`
|
||||
|
||||
error: local variable doesn't need to be boxed here
|
||||
--> $DIR/boxed_local.rs:121:12
|
||||
--> $DIR/boxed_local.rs:123:12
|
||||
|
|
||||
LL | pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: local variable doesn't need to be boxed here
|
||||
--> $DIR/boxed_local.rs:185:44
|
||||
--> $DIR/boxed_local.rs:188:44
|
||||
|
|
||||
LL | fn default_impl_x(self: Box<Self>, x: Box<u32>) -> u32 {
|
||||
| ^
|
||||
|
||||
error: local variable doesn't need to be boxed here
|
||||
--> $DIR/boxed_local.rs:192:16
|
||||
--> $DIR/boxed_local.rs:196:16
|
||||
|
|
||||
LL | fn foo(x: Box<u32>) {}
|
||||
| ^
|
||||
|
|
|
@ -29,6 +29,8 @@ fn simple_examples() {
|
|||
|
||||
// The rest is self contained and moveable => Only lint the rest
|
||||
let result = false;
|
||||
//~^ ERROR: all if blocks contain the same code at the end
|
||||
//~| NOTE: the end suggestion probably needs some adjustments to use the expressio
|
||||
println!("Block end!");
|
||||
result
|
||||
};
|
||||
|
@ -47,6 +49,7 @@ fn simple_examples() {
|
|||
} else {
|
||||
println!("This is also eq with the else block");
|
||||
println!("Same end of block");
|
||||
//~^ ERROR: all if blocks contain the same code at the end
|
||||
}
|
||||
|
||||
// Use of outer scope value
|
||||
|
@ -64,6 +67,7 @@ fn simple_examples() {
|
|||
println!("I'm a local because I use the value `z`: `{}`", z);
|
||||
|
||||
println!(
|
||||
//~^ ERROR: all if blocks contain the same code at the end
|
||||
"I'm moveable because I know: `outer_scope_value`: '{}'",
|
||||
outer_scope_value
|
||||
);
|
||||
|
@ -76,6 +80,7 @@ fn simple_examples() {
|
|||
println!("Hello World");
|
||||
} else {
|
||||
println!("Hello World");
|
||||
//~^ ERROR: all if blocks contain the same code at the end
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +97,7 @@ fn simple_but_suggestion_is_invalid() {
|
|||
println!("{}", later_used_value);
|
||||
} else {
|
||||
let later_used_value = "A string value";
|
||||
//~^ ERROR: all if blocks contain the same code at the end
|
||||
println!("{}", later_used_value);
|
||||
// I'm expecting a note about this
|
||||
}
|
||||
|
@ -105,6 +111,7 @@ fn simple_but_suggestion_is_invalid() {
|
|||
println!("Separator print statement");
|
||||
|
||||
let simple_examples = "I now identify as a &str :)";
|
||||
//~^ ERROR: all if blocks contain the same code at the end
|
||||
println!("This is the new simple_example: {}", simple_examples);
|
||||
}
|
||||
simple_examples();
|
||||
|
@ -170,6 +177,8 @@ fn added_note_for_expression_use() -> u32 {
|
|||
} else {
|
||||
let _ = 6;
|
||||
x << 2
|
||||
//~^ ERROR: all if blocks contain the same code at the end
|
||||
//~| NOTE: the end suggestion probably needs some adjustments to use the expressio
|
||||
};
|
||||
|
||||
if x == 9 {
|
||||
|
@ -177,6 +186,8 @@ fn added_note_for_expression_use() -> u32 {
|
|||
} else {
|
||||
let _ = 17;
|
||||
x * 4
|
||||
//~^ ERROR: all if blocks contain the same code at the end
|
||||
//~| NOTE: the end suggestion probably needs some adjustments to use the expressio
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,6 +200,7 @@ fn test_suggestion_with_weird_formatting() {
|
|||
// The error message still looks weird tbh but this is the best I can do
|
||||
// for weird formatting
|
||||
if x == 17 { b = 1; a = 0x99; } else { a = 0x99; }
|
||||
//~^ ERROR: all if blocks contain the same code at the end
|
||||
}
|
||||
|
||||
fn fp_test() {
|
||||
|
|
|
@ -2,6 +2,8 @@ error: all if blocks contain the same code at the end
|
|||
--> $DIR/shared_at_bottom.rs:31:5
|
||||
|
|
||||
LL | / let result = false;
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | println!("Block end!");
|
||||
LL | | result
|
||||
LL | | };
|
||||
|
@ -17,14 +19,17 @@ help: consider moving these statements after the if
|
|||
|
|
||||
LL ~ }
|
||||
LL + let result = false;
|
||||
LL +
|
||||
LL +
|
||||
LL + println!("Block end!");
|
||||
LL ~ result;
|
||||
|
|
||||
|
||||
error: all if blocks contain the same code at the end
|
||||
--> $DIR/shared_at_bottom.rs:49:5
|
||||
--> $DIR/shared_at_bottom.rs:51:5
|
||||
|
|
||||
LL | / println!("Same end of block");
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
|
@ -35,9 +40,10 @@ LL + println!("Same end of block");
|
|||
|
|
||||
|
||||
error: all if blocks contain the same code at the end
|
||||
--> $DIR/shared_at_bottom.rs:66:5
|
||||
--> $DIR/shared_at_bottom.rs:69:5
|
||||
|
|
||||
LL | / println!(
|
||||
LL | |
|
||||
LL | | "I'm moveable because I know: `outer_scope_value`: '{}'",
|
||||
LL | | outer_scope_value
|
||||
LL | | );
|
||||
|
@ -48,15 +54,17 @@ help: consider moving these statements after the if
|
|||
|
|
||||
LL ~ }
|
||||
LL + println!(
|
||||
LL +
|
||||
LL + "I'm moveable because I know: `outer_scope_value`: '{}'",
|
||||
LL + outer_scope_value
|
||||
LL + );
|
||||
|
|
||||
|
||||
error: all if blocks contain the same code at the end
|
||||
--> $DIR/shared_at_bottom.rs:78:9
|
||||
--> $DIR/shared_at_bottom.rs:82:9
|
||||
|
|
||||
LL | / println!("Hello World");
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_________^
|
||||
|
|
||||
|
@ -67,9 +75,10 @@ LL + println!("Hello World");
|
|||
|
|
||||
|
||||
error: all if blocks contain the same code at the end
|
||||
--> $DIR/shared_at_bottom.rs:94:5
|
||||
--> $DIR/shared_at_bottom.rs:99:5
|
||||
|
|
||||
LL | / let later_used_value = "A string value";
|
||||
LL | |
|
||||
LL | | println!("{}", later_used_value);
|
||||
LL | | // I'm expecting a note about this
|
||||
LL | | }
|
||||
|
@ -80,13 +89,15 @@ help: consider moving these statements after the if
|
|||
|
|
||||
LL ~ }
|
||||
LL + let later_used_value = "A string value";
|
||||
LL +
|
||||
LL + println!("{}", later_used_value);
|
||||
|
|
||||
|
||||
error: all if blocks contain the same code at the end
|
||||
--> $DIR/shared_at_bottom.rs:107:5
|
||||
--> $DIR/shared_at_bottom.rs:113:5
|
||||
|
|
||||
LL | / let simple_examples = "I now identify as a &str :)";
|
||||
LL | |
|
||||
LL | | println!("This is the new simple_example: {}", simple_examples);
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
@ -96,13 +107,16 @@ help: consider moving these statements after the if
|
|||
|
|
||||
LL ~ }
|
||||
LL + let simple_examples = "I now identify as a &str :)";
|
||||
LL +
|
||||
LL + println!("This is the new simple_example: {}", simple_examples);
|
||||
|
|
||||
|
||||
error: all if blocks contain the same code at the end
|
||||
--> $DIR/shared_at_bottom.rs:172:5
|
||||
--> $DIR/shared_at_bottom.rs:179:5
|
||||
|
|
||||
LL | / x << 2
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | };
|
||||
| |_____^
|
||||
|
|
||||
|
@ -114,9 +128,11 @@ LL ~ x << 2;
|
|||
|
|
||||
|
||||
error: all if blocks contain the same code at the end
|
||||
--> $DIR/shared_at_bottom.rs:179:5
|
||||
--> $DIR/shared_at_bottom.rs:188:5
|
||||
|
|
||||
LL | / x * 4
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
|
@ -128,7 +144,7 @@ LL + x * 4
|
|||
|
|
||||
|
||||
error: all if blocks contain the same code at the end
|
||||
--> $DIR/shared_at_bottom.rs:191:44
|
||||
--> $DIR/shared_at_bottom.rs:202:44
|
||||
|
|
||||
LL | if x == 17 { b = 1; a = 0x99; } else { a = 0x99; }
|
||||
| ^^^^^^^^^^^
|
||||
|
|
|
@ -9,6 +9,7 @@ fn simple_examples() {
|
|||
|
||||
// Simple
|
||||
if true {
|
||||
//~^ ERROR: all if blocks contain the same code at the start
|
||||
println!("Hello World!");
|
||||
println!("I'm branch nr: 1");
|
||||
} else {
|
||||
|
@ -18,6 +19,7 @@ fn simple_examples() {
|
|||
|
||||
// Else if
|
||||
if x == 0 {
|
||||
//~^ ERROR: all if blocks contain the same code at the start
|
||||
let y = 9;
|
||||
println!("The value y was set to: `{}`", y);
|
||||
let _z = y;
|
||||
|
@ -39,6 +41,7 @@ fn simple_examples() {
|
|||
|
||||
// Return a value
|
||||
let _ = if x == 7 {
|
||||
//~^ ERROR: all if blocks contain the same code at the start
|
||||
let y = 16;
|
||||
println!("What can I say except: \"you're welcome?\"");
|
||||
let _ = y;
|
||||
|
@ -57,6 +60,7 @@ fn simple_but_suggestion_is_invalid() {
|
|||
// Can't be automatically moved because used_value_name is getting used again
|
||||
let used_value_name = 19;
|
||||
if x == 10 {
|
||||
//~^ ERROR: all if blocks contain the same code at the start
|
||||
let used_value_name = "Different type";
|
||||
println!("Str: {}", used_value_name);
|
||||
let _ = 1;
|
||||
|
@ -71,6 +75,7 @@ fn simple_but_suggestion_is_invalid() {
|
|||
let can_be_overridden = 8;
|
||||
let _ = can_be_overridden;
|
||||
if x == 11 {
|
||||
//~^ ERROR: all if blocks contain the same code at the start
|
||||
let can_be_overridden = "Move me";
|
||||
println!("I'm also moveable");
|
||||
let _ = 111;
|
||||
|
@ -87,6 +92,7 @@ fn check_if_same_than_else_mask() {
|
|||
|
||||
#[allow(clippy::if_same_then_else)]
|
||||
if x == 2020 {
|
||||
//~^ ERROR: all if blocks contain the same code at the start
|
||||
println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint.");
|
||||
println!("Because `IF_SAME_THEN_ELSE` is allowed here");
|
||||
} else {
|
||||
|
@ -95,6 +101,7 @@ fn check_if_same_than_else_mask() {
|
|||
}
|
||||
|
||||
if x == 2019 {
|
||||
//~^ ERROR: this `if` has identical blocks
|
||||
println!("This should trigger `IS_SAME_THAN_ELSE` as usual");
|
||||
} else {
|
||||
println!("This should trigger `IS_SAME_THAN_ELSE` as usual");
|
||||
|
|
|
@ -2,6 +2,7 @@ error: all if blocks contain the same code at the start
|
|||
--> $DIR/shared_at_top.rs:11:5
|
||||
|
|
||||
LL | / if true {
|
||||
LL | |
|
||||
LL | | println!("Hello World!");
|
||||
| |_________________________________^
|
||||
|
|
||||
|
@ -17,9 +18,10 @@ LL + if true {
|
|||
|
|
||||
|
||||
error: all if blocks contain the same code at the start
|
||||
--> $DIR/shared_at_top.rs:20:5
|
||||
--> $DIR/shared_at_top.rs:21:5
|
||||
|
|
||||
LL | / if x == 0 {
|
||||
LL | |
|
||||
LL | | let y = 9;
|
||||
LL | | println!("The value y was set to: `{}`", y);
|
||||
LL | | let _z = y;
|
||||
|
@ -35,9 +37,10 @@ LL + if x == 0 {
|
|||
|
|
||||
|
||||
error: all if blocks contain the same code at the start
|
||||
--> $DIR/shared_at_top.rs:41:5
|
||||
--> $DIR/shared_at_top.rs:43:5
|
||||
|
|
||||
LL | / let _ = if x == 7 {
|
||||
LL | |
|
||||
LL | | let y = 16;
|
||||
| |___________________^
|
||||
|
|
||||
|
@ -48,9 +51,10 @@ LL + let _ = if x == 7 {
|
|||
|
|
||||
|
||||
error: all if blocks contain the same code at the start
|
||||
--> $DIR/shared_at_top.rs:59:5
|
||||
--> $DIR/shared_at_top.rs:62:5
|
||||
|
|
||||
LL | / if x == 10 {
|
||||
LL | |
|
||||
LL | | let used_value_name = "Different type";
|
||||
LL | | println!("Str: {}", used_value_name);
|
||||
| |_____________________________________________^
|
||||
|
@ -64,9 +68,10 @@ LL + if x == 10 {
|
|||
|
|
||||
|
||||
error: all if blocks contain the same code at the start
|
||||
--> $DIR/shared_at_top.rs:73:5
|
||||
--> $DIR/shared_at_top.rs:77:5
|
||||
|
|
||||
LL | / if x == 11 {
|
||||
LL | |
|
||||
LL | | let can_be_overridden = "Move me";
|
||||
LL | | println!("I'm also moveable");
|
||||
| |______________________________________^
|
||||
|
@ -80,9 +85,10 @@ LL + if x == 11 {
|
|||
|
|
||||
|
||||
error: all if blocks contain the same code at the start
|
||||
--> $DIR/shared_at_top.rs:89:5
|
||||
--> $DIR/shared_at_top.rs:94:5
|
||||
|
|
||||
LL | / if x == 2020 {
|
||||
LL | |
|
||||
LL | | println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint.");
|
||||
LL | | println!("Because `IF_SAME_THEN_ELSE` is allowed here");
|
||||
| |________________________________________________________________^
|
||||
|
@ -95,16 +101,17 @@ LL + if x == 2020 {
|
|||
|
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/shared_at_top.rs:97:18
|
||||
--> $DIR/shared_at_top.rs:103:18
|
||||
|
|
||||
LL | if x == 2019 {
|
||||
| __________________^
|
||||
LL | |
|
||||
LL | | println!("This should trigger `IS_SAME_THAN_ELSE` as usual");
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/shared_at_top.rs:99:12
|
||||
--> $DIR/shared_at_top.rs:106:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
|
|
|
@ -15,6 +15,7 @@ fn overlapping_eq_regions() {
|
|||
|
||||
// Overlap with separator
|
||||
if x == 7 {
|
||||
//~^ ERROR: all if blocks contain the same code at both the start and the end
|
||||
let t = 7;
|
||||
let _overlap_start = t * 2;
|
||||
let _overlap_end = 2 * t;
|
||||
|
@ -31,6 +32,7 @@ fn overlapping_eq_regions() {
|
|||
|
||||
// Overlap with separator
|
||||
if x == 99 {
|
||||
//~^ ERROR: all if blocks contain the same code at both the start and the end
|
||||
let r = 7;
|
||||
let _overlap_start = r;
|
||||
let _overlap_middle = r * r;
|
||||
|
@ -60,6 +62,7 @@ fn complexer_example() {
|
|||
let x = 8;
|
||||
let y = 9;
|
||||
if (x > 7 && y < 13) || (x + y) % 2 == 1 {
|
||||
//~^ ERROR: all if blocks contain the same code at both the start and the end
|
||||
let a = 0xcafe;
|
||||
let b = 0xffff00ff;
|
||||
let e_id = gen_id(a, b);
|
||||
|
@ -93,6 +96,7 @@ fn added_note_for_expression_use() -> u32 {
|
|||
let x = 9;
|
||||
|
||||
let _ = if x == 7 {
|
||||
//~^ ERROR: all if blocks contain the same code at both the start and the end
|
||||
let _ = 19;
|
||||
|
||||
let _splitter = 6;
|
||||
|
@ -105,6 +109,7 @@ fn added_note_for_expression_use() -> u32 {
|
|||
};
|
||||
|
||||
if x == 9 {
|
||||
//~^ ERROR: all if blocks contain the same code at both the start and the end
|
||||
let _ = 17;
|
||||
|
||||
let _splitter = 6;
|
||||
|
|
|
@ -2,13 +2,14 @@ error: all if blocks contain the same code at both the start and the end
|
|||
--> $DIR/shared_at_top_and_bottom.rs:17:5
|
||||
|
|
||||
LL | / if x == 7 {
|
||||
LL | |
|
||||
LL | | let t = 7;
|
||||
LL | | let _overlap_start = t * 2;
|
||||
LL | | let _overlap_end = 2 * t;
|
||||
| |_________________________________^
|
||||
|
|
||||
note: this code is shared at the end
|
||||
--> $DIR/shared_at_top_and_bottom.rs:29:5
|
||||
--> $DIR/shared_at_top_and_bottom.rs:30:5
|
||||
|
|
||||
LL | / let _u = 9;
|
||||
LL | | }
|
||||
|
@ -32,16 +33,17 @@ LL + let _u = 9;
|
|||
|
|
||||
|
||||
error: all if blocks contain the same code at both the start and the end
|
||||
--> $DIR/shared_at_top_and_bottom.rs:33:5
|
||||
--> $DIR/shared_at_top_and_bottom.rs:34:5
|
||||
|
|
||||
LL | / if x == 99 {
|
||||
LL | |
|
||||
LL | | let r = 7;
|
||||
LL | | let _overlap_start = r;
|
||||
LL | | let _overlap_middle = r * r;
|
||||
| |____________________________________^
|
||||
|
|
||||
note: this code is shared at the end
|
||||
--> $DIR/shared_at_top_and_bottom.rs:44:5
|
||||
--> $DIR/shared_at_top_and_bottom.rs:46:5
|
||||
|
|
||||
LL | / let _overlap_end = r * r * r;
|
||||
LL | | let z = "end";
|
||||
|
@ -63,16 +65,17 @@ LL + let z = "end";
|
|||
|
|
||||
|
||||
error: all if blocks contain the same code at both the start and the end
|
||||
--> $DIR/shared_at_top_and_bottom.rs:62:5
|
||||
--> $DIR/shared_at_top_and_bottom.rs:64:5
|
||||
|
|
||||
LL | / if (x > 7 && y < 13) || (x + y) % 2 == 1 {
|
||||
LL | |
|
||||
LL | | let a = 0xcafe;
|
||||
LL | | let b = 0xffff00ff;
|
||||
LL | | let e_id = gen_id(a, b);
|
||||
| |________________________________^
|
||||
|
|
||||
note: this code is shared at the end
|
||||
--> $DIR/shared_at_top_and_bottom.rs:82:5
|
||||
--> $DIR/shared_at_top_and_bottom.rs:85:5
|
||||
|
|
||||
LL | / let pack = DataPack {
|
||||
LL | | id: e_id,
|
||||
|
@ -102,14 +105,15 @@ LL + process_data(pack);
|
|||
|
|
||||
|
||||
error: all if blocks contain the same code at both the start and the end
|
||||
--> $DIR/shared_at_top_and_bottom.rs:95:5
|
||||
--> $DIR/shared_at_top_and_bottom.rs:98:5
|
||||
|
|
||||
LL | / let _ = if x == 7 {
|
||||
LL | |
|
||||
LL | | let _ = 19;
|
||||
| |___________________^
|
||||
|
|
||||
note: this code is shared at the end
|
||||
--> $DIR/shared_at_top_and_bottom.rs:104:5
|
||||
--> $DIR/shared_at_top_and_bottom.rs:108:5
|
||||
|
|
||||
LL | / x << 2
|
||||
LL | | };
|
||||
|
@ -127,14 +131,15 @@ LL ~ x << 2;
|
|||
|
|
||||
|
||||
error: all if blocks contain the same code at both the start and the end
|
||||
--> $DIR/shared_at_top_and_bottom.rs:107:5
|
||||
--> $DIR/shared_at_top_and_bottom.rs:111:5
|
||||
|
|
||||
LL | / if x == 9 {
|
||||
LL | |
|
||||
LL | | let _ = 17;
|
||||
| |___________________^
|
||||
|
|
||||
note: this code is shared at the end
|
||||
--> $DIR/shared_at_top_and_bottom.rs:116:5
|
||||
--> $DIR/shared_at_top_and_bottom.rs:121:5
|
||||
|
|
||||
LL | / x * 4
|
||||
LL | | }
|
||||
|
|
|
@ -107,6 +107,7 @@ fn valid_examples() {
|
|||
|
||||
// Let's test empty blocks
|
||||
if false {
|
||||
//~^ ERROR: this `if` has identical blocks
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +119,7 @@ fn trigger_other_lint() {
|
|||
|
||||
// Same block
|
||||
if x == 0 {
|
||||
//~^ ERROR: this `if` has identical blocks
|
||||
let u = 19;
|
||||
println!("How are u today?");
|
||||
let _ = "This is a string";
|
||||
|
@ -129,12 +131,14 @@ fn trigger_other_lint() {
|
|||
|
||||
// Only same expression
|
||||
let _ = if x == 6 { 7 } else { 7 };
|
||||
//~^ ERROR: this `if` has identical blocks
|
||||
|
||||
// Same in else if block
|
||||
let _ = if x == 67 {
|
||||
println!("Well I'm the most important block");
|
||||
"I'm a pretty string"
|
||||
} else if x == 68 {
|
||||
//~^ ERROR: this `if` has identical blocks
|
||||
println!("I'm a doppelgänger");
|
||||
// Don't listen to my clone below
|
||||
|
||||
|
@ -149,6 +153,7 @@ fn trigger_other_lint() {
|
|||
if x == 0 {
|
||||
println!("I'm single");
|
||||
} else if x == 68 {
|
||||
//~^ ERROR: this `if` has identical blocks
|
||||
println!("I'm a doppelgänger");
|
||||
// Don't listen to my clone below
|
||||
} else {
|
||||
|
|
|
@ -3,11 +3,12 @@ error: this `if` has identical blocks
|
|||
|
|
||||
LL | if false {
|
||||
| ______________^
|
||||
LL | |
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/valid_if_blocks.rs:110:12
|
||||
--> $DIR/valid_if_blocks.rs:111:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
|
@ -20,10 +21,11 @@ LL | #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)]
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/valid_if_blocks.rs:120:15
|
||||
--> $DIR/valid_if_blocks.rs:121:15
|
||||
|
|
||||
LL | if x == 0 {
|
||||
| _______________^
|
||||
LL | |
|
||||
LL | | let u = 19;
|
||||
LL | | println!("How are u today?");
|
||||
LL | | let _ = "This is a string";
|
||||
|
@ -31,7 +33,7 @@ LL | | } else {
|
|||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/valid_if_blocks.rs:124:12
|
||||
--> $DIR/valid_if_blocks.rs:126:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
|
@ -42,22 +44,23 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/valid_if_blocks.rs:131:23
|
||||
--> $DIR/valid_if_blocks.rs:133:23
|
||||
|
|
||||
LL | let _ = if x == 6 { 7 } else { 7 };
|
||||
| ^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/valid_if_blocks.rs:131:34
|
||||
--> $DIR/valid_if_blocks.rs:133:34
|
||||
|
|
||||
LL | let _ = if x == 6 { 7 } else { 7 };
|
||||
| ^^^^^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/valid_if_blocks.rs:137:23
|
||||
--> $DIR/valid_if_blocks.rs:140:23
|
||||
|
|
||||
LL | } else if x == 68 {
|
||||
| _______________________^
|
||||
LL | |
|
||||
LL | | println!("I'm a doppelgänger");
|
||||
LL | | // Don't listen to my clone below
|
||||
LL | |
|
||||
|
@ -66,7 +69,7 @@ LL | | } else {
|
|||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/valid_if_blocks.rs:142:12
|
||||
--> $DIR/valid_if_blocks.rs:146:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
|
@ -78,17 +81,18 @@ LL | | };
|
|||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/valid_if_blocks.rs:151:23
|
||||
--> $DIR/valid_if_blocks.rs:155:23
|
||||
|
|
||||
LL | } else if x == 68 {
|
||||
| _______________________^
|
||||
LL | |
|
||||
LL | | println!("I'm a doppelgänger");
|
||||
LL | | // Don't listen to my clone below
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/valid_if_blocks.rs:154:12
|
||||
--> $DIR/valid_if_blocks.rs:159:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
|
|
|
@ -8,9 +8,11 @@ fn main() {
|
|||
|
||||
// naive byte count
|
||||
let _ = x.iter().filter(|&&a| a == 0).count();
|
||||
//~^ ERROR: you appear to be counting bytes the naive way
|
||||
|
||||
// naive byte count
|
||||
let _ = (&x[..]).iter().filter(|&a| *a == 0).count();
|
||||
//~^ ERROR: you appear to be counting bytes the naive way
|
||||
|
||||
// not an equality count, OK.
|
||||
let _ = x.iter().filter(|a| **a > 0).count();
|
||||
|
@ -28,6 +30,7 @@ fn main() {
|
|||
|
||||
// naive byte count
|
||||
let _ = x.iter().filter(|a| b + 1 == **a).count();
|
||||
//~^ ERROR: you appear to be counting bytes the naive way
|
||||
|
||||
let y = vec![0_u16; 3];
|
||||
|
||||
|
|
|
@ -11,13 +11,13 @@ LL | #[deny(clippy::naive_bytecount)]
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: you appear to be counting bytes the naive way
|
||||
--> $DIR/bytecount.rs:13:13
|
||||
--> $DIR/bytecount.rs:14:13
|
||||
|
|
||||
LL | let _ = (&x[..]).iter().filter(|&a| *a == 0).count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count((&x[..]), 0)`
|
||||
|
||||
error: you appear to be counting bytes the naive way
|
||||
--> $DIR/bytecount.rs:30:13
|
||||
--> $DIR/bytecount.rs:32:13
|
||||
|
|
||||
LL | let _ = x.iter().filter(|a| b + 1 == **a).count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, b + 1)`
|
||||
|
|
|
@ -14,56 +14,101 @@ fn main() {
|
|||
// Test clippy::cast_precision_loss
|
||||
let x0 = 1i32;
|
||||
x0 as f32;
|
||||
//~^ ERROR: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide,
|
||||
//~| NOTE: `-D clippy::cast-precision-loss` implied by `-D warnings`
|
||||
let x1 = 1i64;
|
||||
x1 as f32;
|
||||
//~^ ERROR: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide,
|
||||
x1 as f64;
|
||||
//~^ ERROR: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide,
|
||||
let x2 = 1u32;
|
||||
x2 as f32;
|
||||
//~^ ERROR: casting `u32` to `f32` causes a loss of precision (`u32` is 32 bits wide,
|
||||
let x3 = 1u64;
|
||||
x3 as f32;
|
||||
//~^ ERROR: casting `u64` to `f32` causes a loss of precision (`u64` is 64 bits wide,
|
||||
x3 as f64;
|
||||
//~^ ERROR: casting `u64` to `f64` causes a loss of precision (`u64` is 64 bits wide,
|
||||
// Test clippy::cast_possible_truncation
|
||||
1f32 as i32;
|
||||
//~^ ERROR: casting `f32` to `i32` may truncate the value
|
||||
1f32 as u32;
|
||||
//~^ ERROR: casting `f32` to `u32` may truncate the value
|
||||
//~| ERROR: casting `f32` to `u32` may lose the sign of the value
|
||||
//~| NOTE: `-D clippy::cast-sign-loss` implied by `-D warnings`
|
||||
1f64 as f32;
|
||||
//~^ ERROR: casting `f64` to `f32` may truncate the value
|
||||
1i32 as i8;
|
||||
//~^ ERROR: casting `i32` to `i8` may truncate the value
|
||||
1i32 as u8;
|
||||
//~^ ERROR: casting `i32` to `u8` may truncate the value
|
||||
1f64 as isize;
|
||||
//~^ ERROR: casting `f64` to `isize` may truncate the value
|
||||
1f64 as usize;
|
||||
//~^ ERROR: casting `f64` to `usize` may truncate the value
|
||||
//~| ERROR: casting `f64` to `usize` may lose the sign of the value
|
||||
1f32 as u32 as u16;
|
||||
//~^ ERROR: casting `u32` to `u16` may truncate the value
|
||||
//~| ERROR: casting `f32` to `u32` may truncate the value
|
||||
//~| ERROR: casting `f32` to `u32` may lose the sign of the value
|
||||
{
|
||||
let _x: i8 = 1i32 as _;
|
||||
//~^ ERROR: casting `i32` to `i8` may truncate the value
|
||||
1f32 as i32;
|
||||
//~^ ERROR: casting `f32` to `i32` may truncate the value
|
||||
1f64 as i32;
|
||||
//~^ ERROR: casting `f64` to `i32` may truncate the value
|
||||
1f32 as u8;
|
||||
//~^ ERROR: casting `f32` to `u8` may truncate the value
|
||||
//~| ERROR: casting `f32` to `u8` may lose the sign of the value
|
||||
}
|
||||
// Test clippy::cast_possible_wrap
|
||||
1u8 as i8;
|
||||
//~^ ERROR: casting `u8` to `i8` may wrap around the value
|
||||
//~| NOTE: `-D clippy::cast-possible-wrap` implied by `-D warnings`
|
||||
1u16 as i16;
|
||||
//~^ ERROR: casting `u16` to `i16` may wrap around the value
|
||||
1u32 as i32;
|
||||
//~^ ERROR: casting `u32` to `i32` may wrap around the value
|
||||
1u64 as i64;
|
||||
//~^ ERROR: casting `u64` to `i64` may wrap around the value
|
||||
1usize as isize;
|
||||
//~^ ERROR: casting `usize` to `isize` may wrap around the value
|
||||
// should not wrap, usize is never 8 bits
|
||||
1usize as i8;
|
||||
//~^ ERROR: casting `usize` to `i8` may truncate the value
|
||||
// wraps on 16 bit ptr size
|
||||
1usize as i16;
|
||||
//~^ ERROR: casting `usize` to `i16` may truncate the value
|
||||
//~| ERROR: casting `usize` to `i16` may wrap around the value on targets with 16-bit
|
||||
//~| NOTE: `usize` and `isize` may be as small as 16 bits on some platforms
|
||||
// wraps on 32 bit ptr size
|
||||
1usize as i32;
|
||||
//~^ ERROR: casting `usize` to `i32` may truncate the value on targets with 64-bit wid
|
||||
//~| ERROR: casting `usize` to `i32` may wrap around the value on targets with 32-bit
|
||||
// wraps on 64 bit ptr size
|
||||
1usize as i64;
|
||||
//~^ ERROR: casting `usize` to `i64` may wrap around the value on targets with 64-bit
|
||||
// should not wrap, isize is never 8 bits
|
||||
1u8 as isize;
|
||||
// wraps on 16 bit ptr size
|
||||
1u16 as isize;
|
||||
//~^ ERROR: casting `u16` to `isize` may wrap around the value on targets with 16-bit
|
||||
//~| NOTE: `usize` and `isize` may be as small as 16 bits on some platforms
|
||||
// wraps on 32 bit ptr size
|
||||
1u32 as isize;
|
||||
//~^ ERROR: casting `u32` to `isize` may wrap around the value on targets with 32-bit
|
||||
// wraps on 64 bit ptr size
|
||||
1u64 as isize;
|
||||
//~^ ERROR: casting `u64` to `isize` may truncate the value on targets with 32-bit wid
|
||||
//~| ERROR: casting `u64` to `isize` may wrap around the value on targets with 64-bit
|
||||
// Test clippy::cast_sign_loss
|
||||
1i32 as u32;
|
||||
-1i32 as u32;
|
||||
//~^ ERROR: casting `i32` to `u32` may lose the sign of the value
|
||||
1isize as usize;
|
||||
-1isize as usize;
|
||||
//~^ ERROR: casting `isize` to `usize` may lose the sign of the value
|
||||
0i8 as u8;
|
||||
i8::MAX as u8;
|
||||
i16::MAX as u16;
|
||||
|
@ -132,6 +177,7 @@ fn main() {
|
|||
// Test for signed min
|
||||
// should be linted because signed
|
||||
(-99999999999i64).min(1) as i8;
|
||||
//~^ ERROR: casting `i64` to `i8` may truncate the value
|
||||
|
||||
// Test for various operations that remove enough bits for the result to fit
|
||||
(999999u64 & 1) as u8;
|
||||
|
@ -145,6 +191,7 @@ fn main() {
|
|||
999999u64.clamp(0, 255) as u8;
|
||||
// should still be linted
|
||||
999999u64.clamp(0, 256) as u8;
|
||||
//~^ ERROR: casting `u64` to `u8` may truncate the value
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum E1 {
|
||||
|
@ -167,7 +214,10 @@ fn main() {
|
|||
impl E2 {
|
||||
fn test(self) {
|
||||
let _ = self as u8;
|
||||
//~^ ERROR: casting `main::E2` to `u8` may truncate the value
|
||||
let _ = Self::B as u8;
|
||||
//~^ ERROR: casting `main::E2::B` to `u8` will truncate the value
|
||||
//~| NOTE: `-D clippy::cast-enum-truncation` implied by `-D warnings`
|
||||
// Don't lint. `255..=256` fits in i16
|
||||
let _ = self as i16;
|
||||
// Don't lint.
|
||||
|
@ -208,7 +258,9 @@ fn main() {
|
|||
impl E5 {
|
||||
fn test(self) {
|
||||
let _ = self as i8;
|
||||
//~^ ERROR: casting `main::E5` to `i8` may truncate the value
|
||||
let _ = Self::A as i8;
|
||||
//~^ ERROR: casting `main::E5::A` to `i8` will truncate the value
|
||||
// Don't lint. `-129..=127` fits in i16
|
||||
let _ = self as i16;
|
||||
// Don't lint.
|
||||
|
@ -225,6 +277,7 @@ fn main() {
|
|||
impl E6 {
|
||||
fn test(self) {
|
||||
let _ = self as i16;
|
||||
//~^ ERROR: casting `main::E6` to `i16` may truncate the value
|
||||
// Don't lint. `2^16-1` fits in u16
|
||||
let _ = Self::A as u16;
|
||||
// Don't lint. `2^16-1..=2^16` fits in u32
|
||||
|
@ -243,6 +296,7 @@ fn main() {
|
|||
impl E7 {
|
||||
fn test(self) {
|
||||
let _ = self as usize;
|
||||
//~^ ERROR: casting `main::E7` to `usize` may truncate the value on targets wi
|
||||
// Don't lint.
|
||||
let _ = Self::A as usize;
|
||||
// Don't lint. `2^32-1..=2^32` fits in u64
|
||||
|
@ -289,6 +343,7 @@ fn main() {
|
|||
impl E10 {
|
||||
fn test(self) {
|
||||
let _ = self as u16;
|
||||
//~^ ERROR: casting `main::E10` to `u16` may truncate the value
|
||||
// Don't lint.
|
||||
let _ = Self::B as u32;
|
||||
// Don't lint.
|
||||
|
@ -299,8 +354,10 @@ fn main() {
|
|||
|
||||
fn avoid_subtract_overflow(q: u32) {
|
||||
let c = (q >> 16) as u8;
|
||||
//~^ ERROR: casting `u32` to `u8` may truncate the value
|
||||
c as usize;
|
||||
|
||||
let c = (q / 1000) as u8;
|
||||
//~^ ERROR: casting `u32` to `u8` may truncate the value
|
||||
c as usize;
|
||||
}
|
||||
|
|
|
@ -7,37 +7,37 @@ LL | x0 as f32;
|
|||
= note: `-D clippy::cast-precision-loss` implied by `-D warnings`
|
||||
|
||||
error: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide)
|
||||
--> $DIR/cast.rs:18:5
|
||||
--> $DIR/cast.rs:20:5
|
||||
|
|
||||
LL | x1 as f32;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
|
||||
--> $DIR/cast.rs:19:5
|
||||
--> $DIR/cast.rs:22:5
|
||||
|
|
||||
LL | x1 as f64;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting `u32` to `f32` causes a loss of precision (`u32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide)
|
||||
--> $DIR/cast.rs:21:5
|
||||
--> $DIR/cast.rs:25:5
|
||||
|
|
||||
LL | x2 as f32;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting `u64` to `f32` causes a loss of precision (`u64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide)
|
||||
--> $DIR/cast.rs:23:5
|
||||
--> $DIR/cast.rs:28:5
|
||||
|
|
||||
LL | x3 as f32;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting `u64` to `f64` causes a loss of precision (`u64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
|
||||
--> $DIR/cast.rs:24:5
|
||||
--> $DIR/cast.rs:30:5
|
||||
|
|
||||
LL | x3 as f64;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting `f32` to `i32` may truncate the value
|
||||
--> $DIR/cast.rs:26:5
|
||||
--> $DIR/cast.rs:33:5
|
||||
|
|
||||
LL | 1f32 as i32;
|
||||
| ^^^^^^^^^^^
|
||||
|
@ -46,7 +46,7 @@ LL | 1f32 as i32;
|
|||
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
|
||||
|
||||
error: casting `f32` to `u32` may truncate the value
|
||||
--> $DIR/cast.rs:27:5
|
||||
--> $DIR/cast.rs:35:5
|
||||
|
|
||||
LL | 1f32 as u32;
|
||||
| ^^^^^^^^^^^
|
||||
|
@ -54,7 +54,7 @@ LL | 1f32 as u32;
|
|||
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
|
||||
|
||||
error: casting `f32` to `u32` may lose the sign of the value
|
||||
--> $DIR/cast.rs:27:5
|
||||
--> $DIR/cast.rs:35:5
|
||||
|
|
||||
LL | 1f32 as u32;
|
||||
| ^^^^^^^^^^^
|
||||
|
@ -62,7 +62,7 @@ LL | 1f32 as u32;
|
|||
= note: `-D clippy::cast-sign-loss` implied by `-D warnings`
|
||||
|
||||
error: casting `f64` to `f32` may truncate the value
|
||||
--> $DIR/cast.rs:28:5
|
||||
--> $DIR/cast.rs:39:5
|
||||
|
|
||||
LL | 1f64 as f32;
|
||||
| ^^^^^^^^^^^
|
||||
|
@ -70,7 +70,7 @@ LL | 1f64 as f32;
|
|||
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
|
||||
|
||||
error: casting `i32` to `i8` may truncate the value
|
||||
--> $DIR/cast.rs:29:5
|
||||
--> $DIR/cast.rs:41:5
|
||||
|
|
||||
LL | 1i32 as i8;
|
||||
| ^^^^^^^^^^
|
||||
|
@ -82,7 +82,7 @@ LL | i8::try_from(1i32);
|
|||
| ~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `i32` to `u8` may truncate the value
|
||||
--> $DIR/cast.rs:30:5
|
||||
--> $DIR/cast.rs:43:5
|
||||
|
|
||||
LL | 1i32 as u8;
|
||||
| ^^^^^^^^^^
|
||||
|
@ -94,7 +94,7 @@ LL | u8::try_from(1i32);
|
|||
| ~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `f64` to `isize` may truncate the value
|
||||
--> $DIR/cast.rs:31:5
|
||||
--> $DIR/cast.rs:45:5
|
||||
|
|
||||
LL | 1f64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -102,7 +102,7 @@ LL | 1f64 as isize;
|
|||
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
|
||||
|
||||
error: casting `f64` to `usize` may truncate the value
|
||||
--> $DIR/cast.rs:32:5
|
||||
--> $DIR/cast.rs:47:5
|
||||
|
|
||||
LL | 1f64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -110,13 +110,13 @@ LL | 1f64 as usize;
|
|||
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
|
||||
|
||||
error: casting `f64` to `usize` may lose the sign of the value
|
||||
--> $DIR/cast.rs:32:5
|
||||
--> $DIR/cast.rs:47:5
|
||||
|
|
||||
LL | 1f64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting `u32` to `u16` may truncate the value
|
||||
--> $DIR/cast.rs:33:5
|
||||
--> $DIR/cast.rs:50:5
|
||||
|
|
||||
LL | 1f32 as u32 as u16;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
@ -128,7 +128,7 @@ LL | u16::try_from(1f32 as u32);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `f32` to `u32` may truncate the value
|
||||
--> $DIR/cast.rs:33:5
|
||||
--> $DIR/cast.rs:50:5
|
||||
|
|
||||
LL | 1f32 as u32 as u16;
|
||||
| ^^^^^^^^^^^
|
||||
|
@ -136,13 +136,13 @@ LL | 1f32 as u32 as u16;
|
|||
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
|
||||
|
||||
error: casting `f32` to `u32` may lose the sign of the value
|
||||
--> $DIR/cast.rs:33:5
|
||||
--> $DIR/cast.rs:50:5
|
||||
|
|
||||
LL | 1f32 as u32 as u16;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting `i32` to `i8` may truncate the value
|
||||
--> $DIR/cast.rs:35:22
|
||||
--> $DIR/cast.rs:55:22
|
||||
|
|
||||
LL | let _x: i8 = 1i32 as _;
|
||||
| ^^^^^^^^^
|
||||
|
@ -154,7 +154,7 @@ LL | let _x: i8 = 1i32.try_into();
|
|||
| ~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `f32` to `i32` may truncate the value
|
||||
--> $DIR/cast.rs:36:9
|
||||
--> $DIR/cast.rs:57:9
|
||||
|
|
||||
LL | 1f32 as i32;
|
||||
| ^^^^^^^^^^^
|
||||
|
@ -162,7 +162,7 @@ LL | 1f32 as i32;
|
|||
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
|
||||
|
||||
error: casting `f64` to `i32` may truncate the value
|
||||
--> $DIR/cast.rs:37:9
|
||||
--> $DIR/cast.rs:59:9
|
||||
|
|
||||
LL | 1f64 as i32;
|
||||
| ^^^^^^^^^^^
|
||||
|
@ -170,7 +170,7 @@ LL | 1f64 as i32;
|
|||
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
|
||||
|
||||
error: casting `f32` to `u8` may truncate the value
|
||||
--> $DIR/cast.rs:38:9
|
||||
--> $DIR/cast.rs:61:9
|
||||
|
|
||||
LL | 1f32 as u8;
|
||||
| ^^^^^^^^^^
|
||||
|
@ -178,13 +178,13 @@ LL | 1f32 as u8;
|
|||
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
|
||||
|
||||
error: casting `f32` to `u8` may lose the sign of the value
|
||||
--> $DIR/cast.rs:38:9
|
||||
--> $DIR/cast.rs:61:9
|
||||
|
|
||||
LL | 1f32 as u8;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: casting `u8` to `i8` may wrap around the value
|
||||
--> $DIR/cast.rs:41:5
|
||||
--> $DIR/cast.rs:66:5
|
||||
|
|
||||
LL | 1u8 as i8;
|
||||
| ^^^^^^^^^
|
||||
|
@ -192,31 +192,31 @@ LL | 1u8 as i8;
|
|||
= note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
|
||||
|
||||
error: casting `u16` to `i16` may wrap around the value
|
||||
--> $DIR/cast.rs:42:5
|
||||
--> $DIR/cast.rs:69:5
|
||||
|
|
||||
LL | 1u16 as i16;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting `u32` to `i32` may wrap around the value
|
||||
--> $DIR/cast.rs:43:5
|
||||
--> $DIR/cast.rs:71:5
|
||||
|
|
||||
LL | 1u32 as i32;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting `u64` to `i64` may wrap around the value
|
||||
--> $DIR/cast.rs:44:5
|
||||
--> $DIR/cast.rs:73:5
|
||||
|
|
||||
LL | 1u64 as i64;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting `usize` to `isize` may wrap around the value
|
||||
--> $DIR/cast.rs:45:5
|
||||
--> $DIR/cast.rs:75:5
|
||||
|
|
||||
LL | 1usize as isize;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: casting `usize` to `i8` may truncate the value
|
||||
--> $DIR/cast.rs:47:5
|
||||
--> $DIR/cast.rs:78:5
|
||||
|
|
||||
LL | 1usize as i8;
|
||||
| ^^^^^^^^^^^^
|
||||
|
@ -228,7 +228,7 @@ LL | i8::try_from(1usize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `usize` to `i16` may truncate the value
|
||||
--> $DIR/cast.rs:49:5
|
||||
--> $DIR/cast.rs:81:5
|
||||
|
|
||||
LL | 1usize as i16;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -240,7 +240,7 @@ LL | i16::try_from(1usize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers
|
||||
--> $DIR/cast.rs:49:5
|
||||
--> $DIR/cast.rs:81:5
|
||||
|
|
||||
LL | 1usize as i16;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -249,7 +249,7 @@ LL | 1usize as i16;
|
|||
= note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types
|
||||
|
||||
error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast.rs:51:5
|
||||
--> $DIR/cast.rs:86:5
|
||||
|
|
||||
LL | 1usize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -261,19 +261,19 @@ LL | i32::try_from(1usize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast.rs:51:5
|
||||
--> $DIR/cast.rs:86:5
|
||||
|
|
||||
LL | 1usize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting `usize` to `i64` may wrap around the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast.rs:53:5
|
||||
--> $DIR/cast.rs:90:5
|
||||
|
|
||||
LL | 1usize as i64;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting `u16` to `isize` may wrap around the value on targets with 16-bit wide pointers
|
||||
--> $DIR/cast.rs:57:5
|
||||
--> $DIR/cast.rs:95:5
|
||||
|
|
||||
LL | 1u16 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -282,13 +282,13 @@ LL | 1u16 as isize;
|
|||
= note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types
|
||||
|
||||
error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast.rs:59:5
|
||||
--> $DIR/cast.rs:99:5
|
||||
|
|
||||
LL | 1u32 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast.rs:61:5
|
||||
--> $DIR/cast.rs:102:5
|
||||
|
|
||||
LL | 1u64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -300,25 +300,25 @@ LL | isize::try_from(1u64);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast.rs:61:5
|
||||
--> $DIR/cast.rs:102:5
|
||||
|
|
||||
LL | 1u64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting `i32` to `u32` may lose the sign of the value
|
||||
--> $DIR/cast.rs:64:5
|
||||
--> $DIR/cast.rs:107:5
|
||||
|
|
||||
LL | -1i32 as u32;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: casting `isize` to `usize` may lose the sign of the value
|
||||
--> $DIR/cast.rs:66:5
|
||||
--> $DIR/cast.rs:110:5
|
||||
|
|
||||
LL | -1isize as usize;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: casting `i64` to `i8` may truncate the value
|
||||
--> $DIR/cast.rs:134:5
|
||||
--> $DIR/cast.rs:179:5
|
||||
|
|
||||
LL | (-99999999999i64).min(1) as i8;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -330,7 +330,7 @@ LL | i8::try_from((-99999999999i64).min(1));
|
|||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `u64` to `u8` may truncate the value
|
||||
--> $DIR/cast.rs:147:5
|
||||
--> $DIR/cast.rs:193:5
|
||||
|
|
||||
LL | 999999u64.clamp(0, 256) as u8;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -342,7 +342,7 @@ LL | u8::try_from(999999u64.clamp(0, 256));
|
|||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `main::E2` to `u8` may truncate the value
|
||||
--> $DIR/cast.rs:169:21
|
||||
--> $DIR/cast.rs:216:21
|
||||
|
|
||||
LL | let _ = self as u8;
|
||||
| ^^^^^^^^^^
|
||||
|
@ -354,7 +354,7 @@ LL | let _ = u8::try_from(self);
|
|||
| ~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `main::E2::B` to `u8` will truncate the value
|
||||
--> $DIR/cast.rs:170:21
|
||||
--> $DIR/cast.rs:218:21
|
||||
|
|
||||
LL | let _ = Self::B as u8;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -362,7 +362,7 @@ LL | let _ = Self::B as u8;
|
|||
= note: `-D clippy::cast-enum-truncation` implied by `-D warnings`
|
||||
|
||||
error: casting `main::E5` to `i8` may truncate the value
|
||||
--> $DIR/cast.rs:210:21
|
||||
--> $DIR/cast.rs:260:21
|
||||
|
|
||||
LL | let _ = self as i8;
|
||||
| ^^^^^^^^^^
|
||||
|
@ -374,13 +374,13 @@ LL | let _ = i8::try_from(self);
|
|||
| ~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `main::E5::A` to `i8` will truncate the value
|
||||
--> $DIR/cast.rs:211:21
|
||||
--> $DIR/cast.rs:262:21
|
||||
|
|
||||
LL | let _ = Self::A as i8;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting `main::E6` to `i16` may truncate the value
|
||||
--> $DIR/cast.rs:227:21
|
||||
--> $DIR/cast.rs:279:21
|
||||
|
|
||||
LL | let _ = self as i16;
|
||||
| ^^^^^^^^^^^
|
||||
|
@ -392,7 +392,7 @@ LL | let _ = i16::try_from(self);
|
|||
| ~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast.rs:245:21
|
||||
--> $DIR/cast.rs:298:21
|
||||
|
|
||||
LL | let _ = self as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -404,7 +404,7 @@ LL | let _ = usize::try_from(self);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `main::E10` to `u16` may truncate the value
|
||||
--> $DIR/cast.rs:291:21
|
||||
--> $DIR/cast.rs:345:21
|
||||
|
|
||||
LL | let _ = self as u16;
|
||||
| ^^^^^^^^^^^
|
||||
|
@ -416,7 +416,7 @@ LL | let _ = u16::try_from(self);
|
|||
| ~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `u32` to `u8` may truncate the value
|
||||
--> $DIR/cast.rs:301:13
|
||||
--> $DIR/cast.rs:356:13
|
||||
|
|
||||
LL | let c = (q >> 16) as u8;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
@ -428,7 +428,7 @@ LL | let c = u8::try_from(q >> 16);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `u32` to `u8` may truncate the value
|
||||
--> $DIR/cast.rs:304:13
|
||||
--> $DIR/cast.rs:360:13
|
||||
|
|
||||
LL | let c = (q / 1000) as u8;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -17,11 +17,16 @@ fn main() {
|
|||
|
||||
// cast to more-strictly-aligned type
|
||||
(&1u8 as *const u8) as *const u16;
|
||||
//~^ ERROR: casting from `*const u8` to a more-strictly-aligned pointer (`*const u16`)
|
||||
//~| NOTE: `-D clippy::cast-ptr-alignment` implied by `-D warnings`
|
||||
(&mut 1u8 as *mut u8) as *mut u16;
|
||||
//~^ ERROR: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1
|
||||
|
||||
// cast to more-strictly-aligned type, but with the `pointer::cast` function.
|
||||
(&1u8 as *const u8).cast::<u16>();
|
||||
//~^ ERROR: casting from `*const u8` to a more-strictly-aligned pointer (`*const u16`)
|
||||
(&mut 1u8 as *mut u8).cast::<u16>();
|
||||
//~^ ERROR: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1
|
||||
|
||||
/* These should be ok */
|
||||
|
||||
|
|
|
@ -7,19 +7,19 @@ LL | (&1u8 as *const u8) as *const u16;
|
|||
= note: `-D clippy::cast-ptr-alignment` implied by `-D warnings`
|
||||
|
||||
error: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 < 2 bytes)
|
||||
--> $DIR/cast_alignment.rs:20:5
|
||||
--> $DIR/cast_alignment.rs:22:5
|
||||
|
|
||||
LL | (&mut 1u8 as *mut u8) as *mut u16;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: casting from `*const u8` to a more-strictly-aligned pointer (`*const u16`) (1 < 2 bytes)
|
||||
--> $DIR/cast_alignment.rs:23:5
|
||||
--> $DIR/cast_alignment.rs:26:5
|
||||
|
|
||||
LL | (&1u8 as *const u8).cast::<u16>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 < 2 bytes)
|
||||
--> $DIR/cast_alignment.rs:24:5
|
||||
--> $DIR/cast_alignment.rs:28:5
|
||||
|
|
||||
LL | (&mut 1u8 as *mut u8).cast::<u16>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -11,7 +11,10 @@ fn main() {
|
|||
}
|
||||
|
||||
let _ = Foo::Y as usize;
|
||||
//~^ ERROR: cast of an enum tuple constructor to an integer
|
||||
//~| NOTE: `-D clippy::cast-enum-constructor` implied by `-D warnings`
|
||||
let _ = Foo::Y as isize;
|
||||
//~^ ERROR: cast of an enum tuple constructor to an integer
|
||||
let _ = Foo::Y as fn(u32) -> Foo;
|
||||
let _ = Bar::X as usize;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ LL | let _ = Foo::Y as usize;
|
|||
= note: `-D clippy::cast-enum-constructor` implied by `-D warnings`
|
||||
|
||||
error: cast of an enum tuple constructor to an integer
|
||||
--> $DIR/cast_enum_constructor.rs:14:13
|
||||
--> $DIR/cast_enum_constructor.rs:16:13
|
||||
|
|
||||
LL | let _ = Foo::Y as isize;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -3,12 +3,24 @@
|
|||
|
||||
fn main() {
|
||||
let _ = (0.0_f32 / -0.0) as usize;
|
||||
//~^ ERROR: casting a known NaN to usize
|
||||
//~| NOTE: this always evaluates to 0
|
||||
let _ = (f64::INFINITY * -0.0) as usize;
|
||||
//~^ ERROR: casting a known NaN to usize
|
||||
//~| NOTE: this always evaluates to 0
|
||||
let _ = (0.0 * f32::INFINITY) as usize;
|
||||
//~^ ERROR: casting a known NaN to usize
|
||||
//~| NOTE: this always evaluates to 0
|
||||
|
||||
let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize;
|
||||
//~^ ERROR: casting a known NaN to usize
|
||||
//~| NOTE: this always evaluates to 0
|
||||
let _ = (f32::INFINITY - f32::INFINITY) as usize;
|
||||
//~^ ERROR: casting a known NaN to usize
|
||||
//~| NOTE: this always evaluates to 0
|
||||
let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize;
|
||||
//~^ ERROR: casting a known NaN to usize
|
||||
//~| NOTE: this always evaluates to 0
|
||||
|
||||
// those won't be linted:
|
||||
let _ = (1.0_f32 / 0.0) as usize;
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | let _ = (0.0_f32 / -0.0) as usize;
|
|||
= note: `-D clippy::cast-nan-to-int` implied by `-D warnings`
|
||||
|
||||
error: casting a known NaN to usize
|
||||
--> $DIR/cast_nan_to_int.rs:6:13
|
||||
--> $DIR/cast_nan_to_int.rs:8:13
|
||||
|
|
||||
LL | let _ = (f64::INFINITY * -0.0) as usize;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -16,7 +16,7 @@ LL | let _ = (f64::INFINITY * -0.0) as usize;
|
|||
= note: this always evaluates to 0
|
||||
|
||||
error: casting a known NaN to usize
|
||||
--> $DIR/cast_nan_to_int.rs:7:13
|
||||
--> $DIR/cast_nan_to_int.rs:11:13
|
||||
|
|
||||
LL | let _ = (0.0 * f32::INFINITY) as usize;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -24,7 +24,7 @@ LL | let _ = (0.0 * f32::INFINITY) as usize;
|
|||
= note: this always evaluates to 0
|
||||
|
||||
error: casting a known NaN to usize
|
||||
--> $DIR/cast_nan_to_int.rs:9:13
|
||||
--> $DIR/cast_nan_to_int.rs:15:13
|
||||
|
|
||||
LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -32,7 +32,7 @@ LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize;
|
|||
= note: this always evaluates to 0
|
||||
|
||||
error: casting a known NaN to usize
|
||||
--> $DIR/cast_nan_to_int.rs:10:13
|
||||
--> $DIR/cast_nan_to_int.rs:18:13
|
||||
|
|
||||
LL | let _ = (f32::INFINITY - f32::INFINITY) as usize;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -40,7 +40,7 @@ LL | let _ = (f32::INFINITY - f32::INFINITY) as usize;
|
|||
= note: this always evaluates to 0
|
||||
|
||||
error: casting a known NaN to usize
|
||||
--> $DIR/cast_nan_to_int.rs:11:13
|
||||
--> $DIR/cast_nan_to_int.rs:21:13
|
||||
|
|
||||
LL | let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -10,27 +10,47 @@
|
|||
fn main() {
|
||||
// Casting from *size
|
||||
1isize as i8;
|
||||
//~^ ERROR: casting `isize` to `i8` may truncate the value
|
||||
let x0 = 1isize;
|
||||
let x1 = 1usize;
|
||||
x0 as f64;
|
||||
//~^ ERROR: casting `isize` to `f64` causes a loss of precision on targets with 64-bit
|
||||
//~| NOTE: `-D clippy::cast-precision-loss` implied by `-D warnings`
|
||||
x1 as f64;
|
||||
//~^ ERROR: casting `usize` to `f64` causes a loss of precision on targets with 64-bit
|
||||
x0 as f32;
|
||||
//~^ ERROR: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 b
|
||||
x1 as f32;
|
||||
//~^ ERROR: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 b
|
||||
1isize as i32;
|
||||
//~^ ERROR: casting `isize` to `i32` may truncate the value on targets with 64-bit wid
|
||||
1isize as u32;
|
||||
//~^ ERROR: casting `isize` to `u32` may truncate the value on targets with 64-bit wid
|
||||
1usize as u32;
|
||||
//~^ ERROR: casting `usize` to `u32` may truncate the value on targets with 64-bit wid
|
||||
1usize as i32;
|
||||
//~^ ERROR: casting `usize` to `i32` may truncate the value on targets with 64-bit wid
|
||||
//~| ERROR: casting `usize` to `i32` may wrap around the value on targets with 32-bit
|
||||
//~| NOTE: `-D clippy::cast-possible-wrap` implied by `-D warnings`
|
||||
// Casting to *size
|
||||
1i64 as isize;
|
||||
//~^ ERROR: casting `i64` to `isize` may truncate the value on targets with 32-bit wid
|
||||
1i64 as usize;
|
||||
//~^ ERROR: casting `i64` to `usize` may truncate the value on targets with 32-bit wid
|
||||
1u64 as isize;
|
||||
//~^ ERROR: casting `u64` to `isize` may truncate the value on targets with 32-bit wid
|
||||
//~| ERROR: casting `u64` to `isize` may wrap around the value on targets with 64-bit
|
||||
1u64 as usize;
|
||||
//~^ ERROR: casting `u64` to `usize` may truncate the value on targets with 32-bit wid
|
||||
1u32 as isize;
|
||||
//~^ ERROR: casting `u32` to `isize` may wrap around the value on targets with 32-bit
|
||||
1u32 as usize; // Should not trigger any lint
|
||||
1i32 as isize; // Neither should this
|
||||
1i32 as usize;
|
||||
// Big integer literal to float
|
||||
999_999_999 as f32;
|
||||
//~^ ERROR: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide,
|
||||
9_999_999_999_999_999usize as f64;
|
||||
//~^ ERROR: casting `usize` to `f64` causes a loss of precision on targets with 64-bit
|
||||
}
|
||||
//@no-rustfix
|
||||
|
|
|
@ -12,7 +12,7 @@ LL | i8::try_from(1isize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
|
||||
--> $DIR/cast_size.rs:15:5
|
||||
--> $DIR/cast_size.rs:16:5
|
||||
|
|
||||
LL | x0 as f64;
|
||||
| ^^^^^^^^^
|
||||
|
@ -20,25 +20,25 @@ LL | x0 as f64;
|
|||
= note: `-D clippy::cast-precision-loss` implied by `-D warnings`
|
||||
|
||||
error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
|
||||
--> $DIR/cast_size.rs:16:5
|
||||
--> $DIR/cast_size.rs:19:5
|
||||
|
|
||||
LL | x1 as f64;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide)
|
||||
--> $DIR/cast_size.rs:17:5
|
||||
--> $DIR/cast_size.rs:21:5
|
||||
|
|
||||
LL | x0 as f32;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide)
|
||||
--> $DIR/cast_size.rs:18:5
|
||||
--> $DIR/cast_size.rs:23:5
|
||||
|
|
||||
LL | x1 as f32;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:19:5
|
||||
--> $DIR/cast_size.rs:25:5
|
||||
|
|
||||
LL | 1isize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -50,7 +50,7 @@ LL | i32::try_from(1isize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:20:5
|
||||
--> $DIR/cast_size.rs:27:5
|
||||
|
|
||||
LL | 1isize as u32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -62,7 +62,7 @@ LL | u32::try_from(1isize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:21:5
|
||||
--> $DIR/cast_size.rs:29:5
|
||||
|
|
||||
LL | 1usize as u32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -74,7 +74,7 @@ LL | u32::try_from(1usize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:22:5
|
||||
--> $DIR/cast_size.rs:31:5
|
||||
|
|
||||
LL | 1usize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -86,7 +86,7 @@ LL | i32::try_from(1usize);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:22:5
|
||||
--> $DIR/cast_size.rs:31:5
|
||||
|
|
||||
LL | 1usize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -94,7 +94,7 @@ LL | 1usize as i32;
|
|||
= note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
|
||||
|
||||
error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:24:5
|
||||
--> $DIR/cast_size.rs:36:5
|
||||
|
|
||||
LL | 1i64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -106,7 +106,7 @@ LL | isize::try_from(1i64);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:25:5
|
||||
--> $DIR/cast_size.rs:38:5
|
||||
|
|
||||
LL | 1i64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -118,7 +118,7 @@ LL | usize::try_from(1i64);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:26:5
|
||||
--> $DIR/cast_size.rs:40:5
|
||||
|
|
||||
LL | 1u64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -130,13 +130,13 @@ LL | isize::try_from(1u64);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:26:5
|
||||
--> $DIR/cast_size.rs:40:5
|
||||
|
|
||||
LL | 1u64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:27:5
|
||||
--> $DIR/cast_size.rs:43:5
|
||||
|
|
||||
LL | 1u64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -148,19 +148,19 @@ LL | usize::try_from(1u64);
|
|||
| ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:28:5
|
||||
--> $DIR/cast_size.rs:45:5
|
||||
|
|
||||
LL | 1u32 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide)
|
||||
--> $DIR/cast_size.rs:33:5
|
||||
--> $DIR/cast_size.rs:51:5
|
||||
|
|
||||
LL | 999_999_999 as f32;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
|
||||
--> $DIR/cast_size.rs:34:5
|
||||
--> $DIR/cast_size.rs:53:5
|
||||
|
|
||||
LL | 9_999_999_999_999_999usize as f64;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -10,26 +10,47 @@
|
|||
fn main() {
|
||||
// Casting from *size
|
||||
1isize as i8;
|
||||
//~^ ERROR: casting `isize` to `i8` may truncate the value
|
||||
let x0 = 1isize;
|
||||
let x1 = 1usize;
|
||||
x0 as f64;
|
||||
//~^ ERROR: casting `isize` to `f64` causes a loss of precision on targets with 64-bit
|
||||
//~| NOTE: `-D clippy::cast-precision-loss` implied by `-D warnings`
|
||||
x1 as f64;
|
||||
//~^ ERROR: casting `usize` to `f64` causes a loss of precision on targets with 64-bit
|
||||
x0 as f32;
|
||||
//~^ ERROR: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 b
|
||||
x1 as f32;
|
||||
//~^ ERROR: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 b
|
||||
1isize as i32;
|
||||
//~^ ERROR: casting `isize` to `i32` may truncate the value on targets with 64-bit wid
|
||||
1isize as u32;
|
||||
//~^ ERROR: casting `isize` to `u32` may truncate the value on targets with 64-bit wid
|
||||
1usize as u32;
|
||||
//~^ ERROR: casting `usize` to `u32` may truncate the value on targets with 64-bit wid
|
||||
1usize as i32;
|
||||
//~^ ERROR: casting `usize` to `i32` may truncate the value on targets with 64-bit wid
|
||||
//~| ERROR: casting `usize` to `i32` may wrap around the value on targets with 32-bit
|
||||
//~| NOTE: `-D clippy::cast-possible-wrap` implied by `-D warnings`
|
||||
// Casting to *size
|
||||
1i64 as isize;
|
||||
//~^ ERROR: casting `i64` to `isize` may truncate the value on targets with 32-bit wid
|
||||
1i64 as usize;
|
||||
//~^ ERROR: casting `i64` to `usize` may truncate the value on targets with 32-bit wid
|
||||
1u64 as isize;
|
||||
//~^ ERROR: casting `u64` to `isize` may truncate the value on targets with 32-bit wid
|
||||
//~| ERROR: casting `u64` to `isize` may wrap around the value on targets with 64-bit
|
||||
1u64 as usize;
|
||||
//~^ ERROR: casting `u64` to `usize` may truncate the value on targets with 32-bit wid
|
||||
1u32 as isize;
|
||||
//~^ ERROR: casting `u32` to `isize` may wrap around the value on targets with 32-bit
|
||||
1u32 as usize; // Should not trigger any lint
|
||||
1i32 as isize; // Neither should this
|
||||
1i32 as usize;
|
||||
// Big integer literal to float
|
||||
999_999_999 as f32;
|
||||
//~^ ERROR: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide,
|
||||
3_999_999_999usize as f64;
|
||||
//~^ ERROR: casting integer literal to `f64` is unnecessary
|
||||
//~| NOTE: `-D clippy::unnecessary-cast` implied by `-D warnings`
|
||||
}
|
||||
|
|
|
@ -8,10 +8,14 @@ fn main() {
|
|||
// Because it's separate, it does not check the cast back to something of the same size
|
||||
let a = r_x as *const [i32];
|
||||
let b = a as *const [u8];
|
||||
//~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme
|
||||
//~| NOTE: `#[deny(clippy::cast_slice_different_sizes)]` on by default
|
||||
let c = b as *const [u32];
|
||||
//~^ ERROR: casting between raw pointers to `[u8]` (element size 1) and `[u32]` (eleme
|
||||
|
||||
// loses data
|
||||
let loss = r_x as *const [i32] as *const [u8];
|
||||
//~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme
|
||||
|
||||
// Cast back to same size but different type loses no data, just type conversion
|
||||
// This is weird code but there's no reason for this lint specifically to fire *twice* on it
|
||||
|
@ -19,7 +23,9 @@ fn main() {
|
|||
|
||||
// Check casting through blocks is detected
|
||||
let loss_block_1 = { r_x as *const [i32] } as *const [u8];
|
||||
//~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme
|
||||
let loss_block_2 = {
|
||||
//~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme
|
||||
let _ = ();
|
||||
r_x as *const [i32]
|
||||
} as *const [u8];
|
||||
|
@ -37,6 +43,7 @@ fn main() {
|
|||
|
||||
// Check that the result of a long chain of casts is detected
|
||||
let long_chain_loss = r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8];
|
||||
//~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme
|
||||
let long_chain_restore =
|
||||
r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8] as *const [u32];
|
||||
}
|
||||
|
@ -52,32 +59,40 @@ fn foo2(x: *mut [u8]) -> *mut [u8] {
|
|||
|
||||
// Test that casts as part of function returns work
|
||||
fn bar(x: *mut [u16]) -> *mut [u8] {
|
||||
//~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s
|
||||
x as *mut [u8]
|
||||
}
|
||||
|
||||
fn uwu(x: *mut [u16]) -> *mut [u8] {
|
||||
//~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s
|
||||
x as *mut _
|
||||
}
|
||||
|
||||
fn bar2(x: *mut [u16]) -> *mut [u8] {
|
||||
//~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s
|
||||
x as _
|
||||
}
|
||||
|
||||
// constify
|
||||
fn bar3(x: *mut [u16]) -> *const [u8] {
|
||||
//~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s
|
||||
x as _
|
||||
}
|
||||
|
||||
// unconstify
|
||||
fn bar4(x: *const [u16]) -> *mut [u8] {
|
||||
//~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s
|
||||
x as _
|
||||
}
|
||||
|
||||
// function returns plus blocks
|
||||
fn blocks(x: *mut [u16]) -> *mut [u8] {
|
||||
//~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s
|
||||
({ x }) as _
|
||||
}
|
||||
|
||||
fn more_blocks(x: *mut [u16]) -> *mut [u8] {
|
||||
//~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s
|
||||
{ ({ x }) as _ }
|
||||
//~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (eleme
|
||||
}
|
||||
|
|
|
@ -7,28 +7,29 @@ LL | let b = a as *const [u8];
|
|||
= note: `#[deny(clippy::cast_slice_different_sizes)]` on by default
|
||||
|
||||
error: casting between raw pointers to `[u8]` (element size 1) and `[u32]` (element size 4) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:11:13
|
||||
--> $DIR/cast_slice_different_sizes.rs:13:13
|
||||
|
|
||||
LL | let c = b as *const [u32];
|
||||
| ^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(b as *const u32, ..)`
|
||||
|
||||
error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:14:16
|
||||
--> $DIR/cast_slice_different_sizes.rs:17:16
|
||||
|
|
||||
LL | let loss = r_x as *const [i32] as *const [u8];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(r_x as *const [i32] as *const u8, ..)`
|
||||
|
||||
error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:21:24
|
||||
--> $DIR/cast_slice_different_sizes.rs:25:24
|
||||
|
|
||||
LL | let loss_block_1 = { r_x as *const [i32] } as *const [u8];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts({ r_x as *const [i32] } as *const u8, ..)`
|
||||
|
||||
error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:22:24
|
||||
--> $DIR/cast_slice_different_sizes.rs:27:24
|
||||
|
|
||||
LL | let loss_block_2 = {
|
||||
| ________________________^
|
||||
LL | |
|
||||
LL | | let _ = ();
|
||||
LL | | r_x as *const [i32]
|
||||
LL | | } as *const [u8];
|
||||
|
@ -37,58 +38,44 @@ LL | | } as *const [u8];
|
|||
help: replace with `ptr::slice_from_raw_parts`
|
||||
|
|
||||
LL ~ let loss_block_2 = core::ptr::slice_from_raw_parts({
|
||||
LL +
|
||||
LL + let _ = ();
|
||||
LL + r_x as *const [i32]
|
||||
LL ~ } as *const u8, ..);
|
||||
|
|
||||
|
||||
error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:39:27
|
||||
--> $DIR/cast_slice_different_sizes.rs:45:27
|
||||
|
|
||||
LL | let long_chain_loss = r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(r_x as *const [i32] as *const u8, ..)`
|
||||
|
||||
error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:54:36
|
||||
--> $DIR/cast_slice_different_sizes.rs:61:36
|
||||
|
|
||||
LL | fn bar(x: *mut [u16]) -> *mut [u8] {
|
||||
| ____________________________________^
|
||||
LL | |
|
||||
LL | | x as *mut [u8]
|
||||
LL | | }
|
||||
| |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)`
|
||||
|
||||
error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:58:36
|
||||
--> $DIR/cast_slice_different_sizes.rs:66:36
|
||||
|
|
||||
LL | fn uwu(x: *mut [u16]) -> *mut [u8] {
|
||||
| ____________________________________^
|
||||
LL | |
|
||||
LL | | x as *mut _
|
||||
LL | | }
|
||||
| |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)`
|
||||
|
||||
error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:62:37
|
||||
--> $DIR/cast_slice_different_sizes.rs:71:37
|
||||
|
|
||||
LL | fn bar2(x: *mut [u16]) -> *mut [u8] {
|
||||
| _____________________________________^
|
||||
LL | | x as _
|
||||
LL | | }
|
||||
| |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)`
|
||||
|
||||
error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:67:39
|
||||
|
|
||||
LL | fn bar3(x: *mut [u16]) -> *const [u8] {
|
||||
| _______________________________________^
|
||||
LL | | x as _
|
||||
LL | | }
|
||||
| |_^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(x as *const u8, ..)`
|
||||
|
||||
error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:72:39
|
||||
|
|
||||
LL | fn bar4(x: *const [u16]) -> *mut [u8] {
|
||||
| _______________________________________^
|
||||
LL | |
|
||||
LL | | x as _
|
||||
LL | | }
|
||||
| |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)`
|
||||
|
@ -96,23 +83,46 @@ LL | | }
|
|||
error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:77:39
|
||||
|
|
||||
LL | fn bar3(x: *mut [u16]) -> *const [u8] {
|
||||
| _______________________________________^
|
||||
LL | |
|
||||
LL | | x as _
|
||||
LL | | }
|
||||
| |_^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(x as *const u8, ..)`
|
||||
|
||||
error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:83:39
|
||||
|
|
||||
LL | fn bar4(x: *const [u16]) -> *mut [u8] {
|
||||
| _______________________________________^
|
||||
LL | |
|
||||
LL | | x as _
|
||||
LL | | }
|
||||
| |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)`
|
||||
|
||||
error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:89:39
|
||||
|
|
||||
LL | fn blocks(x: *mut [u16]) -> *mut [u8] {
|
||||
| _______________________________________^
|
||||
LL | |
|
||||
LL | | ({ x }) as _
|
||||
LL | | }
|
||||
| |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)`
|
||||
|
||||
error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:81:44
|
||||
--> $DIR/cast_slice_different_sizes.rs:94:44
|
||||
|
|
||||
LL | fn more_blocks(x: *mut [u16]) -> *mut [u8] {
|
||||
| ____________________________________________^
|
||||
LL | |
|
||||
LL | | { ({ x }) as _ }
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)`
|
||||
|
||||
error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count
|
||||
--> $DIR/cast_slice_different_sizes.rs:82:5
|
||||
--> $DIR/cast_slice_different_sizes.rs:96:5
|
||||
|
|
||||
LL | { ({ x }) as _ }
|
||||
| ^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)`
|
||||
|
|
|
@ -2,11 +2,16 @@
|
|||
|
||||
fn main() {
|
||||
#[cfg(feature = "not-really-a-feature")]
|
||||
//~^ ERROR: feature may misspelled as features
|
||||
//~| NOTE: `-D clippy::maybe-misused-cfg` implied by `-D warnings`
|
||||
let _ = 1 + 2;
|
||||
|
||||
#[cfg(all(feature = "right", feature = "wrong"))]
|
||||
//~^ ERROR: feature may misspelled as features
|
||||
let _ = 1 + 2;
|
||||
|
||||
#[cfg(all(feature = "wrong1", any(feature = "right", feature = "wrong2", feature, features)))]
|
||||
//~^ ERROR: feature may misspelled as features
|
||||
//~| ERROR: feature may misspelled as features
|
||||
let _ = 1 + 2;
|
||||
}
|
||||
|
|
|
@ -2,11 +2,16 @@
|
|||
|
||||
fn main() {
|
||||
#[cfg(features = "not-really-a-feature")]
|
||||
//~^ ERROR: feature may misspelled as features
|
||||
//~| NOTE: `-D clippy::maybe-misused-cfg` implied by `-D warnings`
|
||||
let _ = 1 + 2;
|
||||
|
||||
#[cfg(all(feature = "right", features = "wrong"))]
|
||||
//~^ ERROR: feature may misspelled as features
|
||||
let _ = 1 + 2;
|
||||
|
||||
#[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))]
|
||||
//~^ ERROR: feature may misspelled as features
|
||||
//~| ERROR: feature may misspelled as features
|
||||
let _ = 1 + 2;
|
||||
}
|
||||
|
|
|
@ -7,19 +7,19 @@ LL | #[cfg(features = "not-really-a-feature")]
|
|||
= note: `-D clippy::maybe-misused-cfg` implied by `-D warnings`
|
||||
|
||||
error: feature may misspelled as features
|
||||
--> $DIR/cfg_features.rs:7:34
|
||||
--> $DIR/cfg_features.rs:9:34
|
||||
|
|
||||
LL | #[cfg(all(feature = "right", features = "wrong"))]
|
||||
| ^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong"`
|
||||
|
||||
error: feature may misspelled as features
|
||||
--> $DIR/cfg_features.rs:10:15
|
||||
--> $DIR/cfg_features.rs:13:15
|
||||
|
|
||||
LL | #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))]
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong1"`
|
||||
|
||||
error: feature may misspelled as features
|
||||
--> $DIR/cfg_features.rs:10:59
|
||||
--> $DIR/cfg_features.rs:13:59
|
||||
|
|
||||
LL | #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))]
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong2"`
|
||||
|
|
|
@ -3,4 +3,6 @@
|
|||
fn main() {
|
||||
// no suggestion, since a byte literal won't work.
|
||||
let _ = '❤' as u8;
|
||||
//~^ ERROR: casting a character literal to `u8` truncates
|
||||
//~| NOTE: `char` is four bytes wide, but `u8` is a single byte
|
||||
}
|
||||
|
|
|
@ -11,12 +11,16 @@ fn test_complex_conditions() {
|
|||
if x.is_ok() && y.is_err() {
|
||||
// unnecessary
|
||||
x.unwrap();
|
||||
//~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok`
|
||||
// will panic
|
||||
x.unwrap_err();
|
||||
//~^ ERROR: this call to `unwrap_err()` will always panic
|
||||
// will panic
|
||||
y.unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
// unnecessary
|
||||
y.unwrap_err();
|
||||
//~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_err`
|
||||
} else {
|
||||
// not statically determinable whether any of the following will always succeed or always fail:
|
||||
x.unwrap();
|
||||
|
@ -32,27 +36,37 @@ fn test_complex_conditions() {
|
|||
} else {
|
||||
// will panic
|
||||
x.unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
// unnecessary
|
||||
x.unwrap_err();
|
||||
//~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok`
|
||||
// will panic
|
||||
y.unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
// unnecessary
|
||||
y.unwrap_err();
|
||||
//~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_ok`
|
||||
}
|
||||
let z: Result<(), ()> = Ok(());
|
||||
if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
// unnecessary
|
||||
x.unwrap();
|
||||
//~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok`
|
||||
// will panic
|
||||
x.unwrap_err();
|
||||
//~^ ERROR: this call to `unwrap_err()` will always panic
|
||||
// will panic
|
||||
y.unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
// unnecessary
|
||||
y.unwrap_err();
|
||||
//~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_ok`
|
||||
// unnecessary
|
||||
z.unwrap();
|
||||
//~^ ERROR: called `unwrap` on `z` after checking its variant with `is_err`
|
||||
// will panic
|
||||
z.unwrap_err();
|
||||
//~^ ERROR: this call to `unwrap_err()` will always panic
|
||||
}
|
||||
if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
// not statically determinable whether any of the following will always succeed or always fail:
|
||||
|
@ -62,16 +76,22 @@ fn test_complex_conditions() {
|
|||
} else {
|
||||
// will panic
|
||||
x.unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
// unnecessary
|
||||
x.unwrap_err();
|
||||
//~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok`
|
||||
// unnecessary
|
||||
y.unwrap();
|
||||
//~^ ERROR: called `unwrap` on `y` after checking its variant with `is_ok`
|
||||
// will panic
|
||||
y.unwrap_err();
|
||||
//~^ ERROR: this call to `unwrap_err()` will always panic
|
||||
// will panic
|
||||
z.unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
// unnecessary
|
||||
z.unwrap_err();
|
||||
//~^ ERROR: called `unwrap_err` on `z` after checking its variant with `is_err`
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap_err()` will always panic
|
||||
--> $DIR/complex_conditionals.rs:15:9
|
||||
--> $DIR/complex_conditionals.rs:16:9
|
||||
|
|
||||
LL | if x.is_ok() && y.is_err() {
|
||||
| --------- because of this check
|
||||
|
@ -30,7 +30,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/complex_conditionals.rs:17:9
|
||||
--> $DIR/complex_conditionals.rs:19:9
|
||||
|
|
||||
LL | if x.is_ok() && y.is_err() {
|
||||
| ---------- because of this check
|
||||
|
@ -39,7 +39,7 @@ LL | y.unwrap();
|
|||
| ^^^^^^^^^^
|
||||
|
||||
error: called `unwrap_err` on `y` after checking its variant with `is_err`
|
||||
--> $DIR/complex_conditionals.rs:19:9
|
||||
--> $DIR/complex_conditionals.rs:22:9
|
||||
|
|
||||
LL | if x.is_ok() && y.is_err() {
|
||||
| ---------- the check is happening here
|
||||
|
@ -50,7 +50,7 @@ LL | y.unwrap_err();
|
|||
= help: try using `if let` or `match`
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/complex_conditionals.rs:34:9
|
||||
--> $DIR/complex_conditionals.rs:38:9
|
||||
|
|
||||
LL | if x.is_ok() || y.is_ok() {
|
||||
| --------- because of this check
|
||||
|
@ -59,7 +59,7 @@ LL | x.unwrap();
|
|||
| ^^^^^^^^^^
|
||||
|
||||
error: called `unwrap_err` on `x` after checking its variant with `is_ok`
|
||||
--> $DIR/complex_conditionals.rs:36:9
|
||||
--> $DIR/complex_conditionals.rs:41:9
|
||||
|
|
||||
LL | if x.is_ok() || y.is_ok() {
|
||||
| --------- the check is happening here
|
||||
|
@ -70,7 +70,7 @@ LL | x.unwrap_err();
|
|||
= help: try using `if let` or `match`
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/complex_conditionals.rs:38:9
|
||||
--> $DIR/complex_conditionals.rs:44:9
|
||||
|
|
||||
LL | if x.is_ok() || y.is_ok() {
|
||||
| --------- because of this check
|
||||
|
@ -79,7 +79,7 @@ LL | y.unwrap();
|
|||
| ^^^^^^^^^^
|
||||
|
||||
error: called `unwrap_err` on `y` after checking its variant with `is_ok`
|
||||
--> $DIR/complex_conditionals.rs:40:9
|
||||
--> $DIR/complex_conditionals.rs:47:9
|
||||
|
|
||||
LL | if x.is_ok() || y.is_ok() {
|
||||
| --------- the check is happening here
|
||||
|
@ -90,7 +90,7 @@ LL | y.unwrap_err();
|
|||
= help: try using `if let` or `match`
|
||||
|
||||
error: called `unwrap` on `x` after checking its variant with `is_ok`
|
||||
--> $DIR/complex_conditionals.rs:45:9
|
||||
--> $DIR/complex_conditionals.rs:53:9
|
||||
|
|
||||
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| --------- the check is happening here
|
||||
|
@ -101,7 +101,7 @@ LL | x.unwrap();
|
|||
= help: try using `if let` or `match`
|
||||
|
||||
error: this call to `unwrap_err()` will always panic
|
||||
--> $DIR/complex_conditionals.rs:47:9
|
||||
--> $DIR/complex_conditionals.rs:56:9
|
||||
|
|
||||
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| --------- because of this check
|
||||
|
@ -110,7 +110,7 @@ LL | x.unwrap_err();
|
|||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/complex_conditionals.rs:49:9
|
||||
--> $DIR/complex_conditionals.rs:59:9
|
||||
|
|
||||
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| --------- because of this check
|
||||
|
@ -119,7 +119,7 @@ LL | y.unwrap();
|
|||
| ^^^^^^^^^^
|
||||
|
||||
error: called `unwrap_err` on `y` after checking its variant with `is_ok`
|
||||
--> $DIR/complex_conditionals.rs:51:9
|
||||
--> $DIR/complex_conditionals.rs:62:9
|
||||
|
|
||||
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| --------- the check is happening here
|
||||
|
@ -130,7 +130,7 @@ LL | y.unwrap_err();
|
|||
= help: try using `if let` or `match`
|
||||
|
||||
error: called `unwrap` on `z` after checking its variant with `is_err`
|
||||
--> $DIR/complex_conditionals.rs:53:9
|
||||
--> $DIR/complex_conditionals.rs:65:9
|
||||
|
|
||||
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| ---------- the check is happening here
|
||||
|
@ -141,7 +141,7 @@ LL | z.unwrap();
|
|||
= help: try using `if let` or `match`
|
||||
|
||||
error: this call to `unwrap_err()` will always panic
|
||||
--> $DIR/complex_conditionals.rs:55:9
|
||||
--> $DIR/complex_conditionals.rs:68:9
|
||||
|
|
||||
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| ---------- because of this check
|
||||
|
@ -150,7 +150,7 @@ LL | z.unwrap_err();
|
|||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/complex_conditionals.rs:64:9
|
||||
--> $DIR/complex_conditionals.rs:78:9
|
||||
|
|
||||
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
| --------- because of this check
|
||||
|
@ -159,7 +159,7 @@ LL | x.unwrap();
|
|||
| ^^^^^^^^^^
|
||||
|
||||
error: called `unwrap_err` on `x` after checking its variant with `is_ok`
|
||||
--> $DIR/complex_conditionals.rs:66:9
|
||||
--> $DIR/complex_conditionals.rs:81:9
|
||||
|
|
||||
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
| --------- the check is happening here
|
||||
|
@ -170,7 +170,7 @@ LL | x.unwrap_err();
|
|||
= help: try using `if let` or `match`
|
||||
|
||||
error: called `unwrap` on `y` after checking its variant with `is_ok`
|
||||
--> $DIR/complex_conditionals.rs:68:9
|
||||
--> $DIR/complex_conditionals.rs:84:9
|
||||
|
|
||||
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
| --------- the check is happening here
|
||||
|
@ -181,7 +181,7 @@ LL | y.unwrap();
|
|||
= help: try using `if let` or `match`
|
||||
|
||||
error: this call to `unwrap_err()` will always panic
|
||||
--> $DIR/complex_conditionals.rs:70:9
|
||||
--> $DIR/complex_conditionals.rs:87:9
|
||||
|
|
||||
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
| --------- because of this check
|
||||
|
@ -190,7 +190,7 @@ LL | y.unwrap_err();
|
|||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/complex_conditionals.rs:72:9
|
||||
--> $DIR/complex_conditionals.rs:90:9
|
||||
|
|
||||
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
| ---------- because of this check
|
||||
|
@ -199,7 +199,7 @@ LL | z.unwrap();
|
|||
| ^^^^^^^^^^
|
||||
|
||||
error: called `unwrap_err` on `z` after checking its variant with `is_err`
|
||||
--> $DIR/complex_conditionals.rs:74:9
|
||||
--> $DIR/complex_conditionals.rs:93:9
|
||||
|
|
||||
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
| ---------- the check is happening here
|
||||
|
|
|
@ -11,9 +11,11 @@ fn test_nested() {
|
|||
if x.is_some() {
|
||||
// unnecessary
|
||||
x.unwrap();
|
||||
//~^ ERROR: called `unwrap` on `x` after checking its variant with `is_some`
|
||||
} else {
|
||||
// will panic
|
||||
x.unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/complex_conditionals_nested.rs:16:13
|
||||
--> $DIR/complex_conditionals_nested.rs:17:13
|
||||
|
|
||||
LL | if x.is_some() {
|
||||
| ----------- because of this check
|
||||
|
|
|
@ -45,20 +45,26 @@ fn main() {
|
|||
if x.is_some() {
|
||||
// unnecessary
|
||||
x.unwrap();
|
||||
//~^ ERROR: called `unwrap` on `x` after checking its variant with `is_some`
|
||||
// unnecessary
|
||||
x.expect("an error message");
|
||||
//~^ ERROR: called `expect` on `x` after checking its variant with `is_some`
|
||||
} else {
|
||||
// will panic
|
||||
x.unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
// will panic
|
||||
x.expect("an error message");
|
||||
//~^ ERROR: this call to `expect()` will always panic
|
||||
}
|
||||
if x.is_none() {
|
||||
// will panic
|
||||
x.unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
} else {
|
||||
// unnecessary
|
||||
x.unwrap();
|
||||
//~^ ERROR: called `unwrap` on `x` after checking its variant with `is_none`
|
||||
}
|
||||
m!(x);
|
||||
// ok
|
||||
|
@ -71,28 +77,38 @@ fn main() {
|
|||
if x.is_ok() {
|
||||
// unnecessary
|
||||
x.unwrap();
|
||||
//~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok`
|
||||
// unnecessary
|
||||
x.expect("an error message");
|
||||
//~^ ERROR: called `expect` on `x` after checking its variant with `is_ok`
|
||||
// will panic
|
||||
x.unwrap_err();
|
||||
//~^ ERROR: this call to `unwrap_err()` will always panic
|
||||
} else {
|
||||
// will panic
|
||||
x.unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
// will panic
|
||||
x.expect("an error message");
|
||||
//~^ ERROR: this call to `expect()` will always panic
|
||||
// unnecessary
|
||||
x.unwrap_err();
|
||||
//~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok`
|
||||
}
|
||||
if x.is_err() {
|
||||
// will panic
|
||||
x.unwrap();
|
||||
//~^ ERROR: this call to `unwrap()` will always panic
|
||||
// unnecessary
|
||||
x.unwrap_err();
|
||||
//~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_err`
|
||||
} else {
|
||||
// unnecessary
|
||||
x.unwrap();
|
||||
//~^ ERROR: called `unwrap` on `x` after checking its variant with `is_err`
|
||||
// will panic
|
||||
x.unwrap_err();
|
||||
//~^ ERROR: this call to `unwrap_err()` will always panic
|
||||
}
|
||||
if x.is_ok() {
|
||||
x = Err(());
|
||||
|
|
|
@ -14,7 +14,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `expect` on `x` after checking its variant with `is_some`
|
||||
--> $DIR/simple_conditionals.rs:49:9
|
||||
--> $DIR/simple_conditionals.rs:50:9
|
||||
|
|
||||
LL | if x.is_some() {
|
||||
| -------------- help: try: `if let Some(..) = x`
|
||||
|
@ -23,7 +23,7 @@ LL | x.expect("an error message");
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/simple_conditionals.rs:52:9
|
||||
--> $DIR/simple_conditionals.rs:54:9
|
||||
|
|
||||
LL | if x.is_some() {
|
||||
| ----------- because of this check
|
||||
|
@ -38,7 +38,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `expect()` will always panic
|
||||
--> $DIR/simple_conditionals.rs:54:9
|
||||
--> $DIR/simple_conditionals.rs:57:9
|
||||
|
|
||||
LL | if x.is_some() {
|
||||
| ----------- because of this check
|
||||
|
@ -47,7 +47,7 @@ LL | x.expect("an error message");
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/simple_conditionals.rs:58:9
|
||||
--> $DIR/simple_conditionals.rs:62:9
|
||||
|
|
||||
LL | if x.is_none() {
|
||||
| ----------- because of this check
|
||||
|
@ -56,7 +56,7 @@ LL | x.unwrap();
|
|||
| ^^^^^^^^^^
|
||||
|
||||
error: called `unwrap` on `x` after checking its variant with `is_none`
|
||||
--> $DIR/simple_conditionals.rs:61:9
|
||||
--> $DIR/simple_conditionals.rs:66:9
|
||||
|
|
||||
LL | if x.is_none() {
|
||||
| -------------- help: try: `if let Some(..) = x`
|
||||
|
@ -79,7 +79,7 @@ LL | m!(x);
|
|||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: called `unwrap` on `x` after checking its variant with `is_ok`
|
||||
--> $DIR/simple_conditionals.rs:73:9
|
||||
--> $DIR/simple_conditionals.rs:79:9
|
||||
|
|
||||
LL | if x.is_ok() {
|
||||
| ------------ help: try: `if let Ok(..) = x`
|
||||
|
@ -88,7 +88,7 @@ LL | x.unwrap();
|
|||
| ^^^^^^^^^^
|
||||
|
||||
error: called `expect` on `x` after checking its variant with `is_ok`
|
||||
--> $DIR/simple_conditionals.rs:75:9
|
||||
--> $DIR/simple_conditionals.rs:82:9
|
||||
|
|
||||
LL | if x.is_ok() {
|
||||
| ------------ help: try: `if let Ok(..) = x`
|
||||
|
@ -97,7 +97,7 @@ LL | x.expect("an error message");
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap_err()` will always panic
|
||||
--> $DIR/simple_conditionals.rs:77:9
|
||||
--> $DIR/simple_conditionals.rs:85:9
|
||||
|
|
||||
LL | if x.is_ok() {
|
||||
| --------- because of this check
|
||||
|
@ -106,7 +106,7 @@ LL | x.unwrap_err();
|
|||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/simple_conditionals.rs:80:9
|
||||
--> $DIR/simple_conditionals.rs:89:9
|
||||
|
|
||||
LL | if x.is_ok() {
|
||||
| --------- because of this check
|
||||
|
@ -115,7 +115,7 @@ LL | x.unwrap();
|
|||
| ^^^^^^^^^^
|
||||
|
||||
error: this call to `expect()` will always panic
|
||||
--> $DIR/simple_conditionals.rs:82:9
|
||||
--> $DIR/simple_conditionals.rs:92:9
|
||||
|
|
||||
LL | if x.is_ok() {
|
||||
| --------- because of this check
|
||||
|
@ -124,7 +124,7 @@ LL | x.expect("an error message");
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `unwrap_err` on `x` after checking its variant with `is_ok`
|
||||
--> $DIR/simple_conditionals.rs:84:9
|
||||
--> $DIR/simple_conditionals.rs:95:9
|
||||
|
|
||||
LL | if x.is_ok() {
|
||||
| ------------ help: try: `if let Err(..) = x`
|
||||
|
@ -133,7 +133,7 @@ LL | x.unwrap_err();
|
|||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap()` will always panic
|
||||
--> $DIR/simple_conditionals.rs:88:9
|
||||
--> $DIR/simple_conditionals.rs:100:9
|
||||
|
|
||||
LL | if x.is_err() {
|
||||
| ---------- because of this check
|
||||
|
@ -142,7 +142,7 @@ LL | x.unwrap();
|
|||
| ^^^^^^^^^^
|
||||
|
||||
error: called `unwrap_err` on `x` after checking its variant with `is_err`
|
||||
--> $DIR/simple_conditionals.rs:90:9
|
||||
--> $DIR/simple_conditionals.rs:103:9
|
||||
|
|
||||
LL | if x.is_err() {
|
||||
| ------------- help: try: `if let Err(..) = x`
|
||||
|
@ -151,7 +151,7 @@ LL | x.unwrap_err();
|
|||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: called `unwrap` on `x` after checking its variant with `is_err`
|
||||
--> $DIR/simple_conditionals.rs:93:9
|
||||
--> $DIR/simple_conditionals.rs:107:9
|
||||
|
|
||||
LL | if x.is_err() {
|
||||
| ------------- help: try: `if let Ok(..) = x`
|
||||
|
@ -160,7 +160,7 @@ LL | x.unwrap();
|
|||
| ^^^^^^^^^^
|
||||
|
||||
error: this call to `unwrap_err()` will always panic
|
||||
--> $DIR/simple_conditionals.rs:95:9
|
||||
--> $DIR/simple_conditionals.rs:110:9
|
||||
|
|
||||
LL | if x.is_err() {
|
||||
| ---------- because of this check
|
||||
|
|
|
@ -7,11 +7,14 @@ fn main() {
|
|||
let x = 0;
|
||||
let p: *const usize = &x;
|
||||
if p == ptr::null() {
|
||||
//~^ ERROR: comparing with null is better expressed by the `.is_null()` method
|
||||
//~| NOTE: `-D clippy::cmp-null` implied by `-D warnings`
|
||||
println!("This is surprising!");
|
||||
}
|
||||
let mut y = 0;
|
||||
let mut m: *mut usize = &mut y;
|
||||
if m == ptr::null_mut() {
|
||||
//~^ ERROR: comparing with null is better expressed by the `.is_null()` method
|
||||
println!("This is surprising, too!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ LL | if p == ptr::null() {
|
|||
= note: `-D clippy::cmp-null` implied by `-D warnings`
|
||||
|
||||
error: comparing with null is better expressed by the `.is_null()` method
|
||||
--> $DIR/cmp_null.rs:14:8
|
||||
--> $DIR/cmp_null.rs:16:8
|
||||
|
|
||||
LL | if m == ptr::null_mut() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -5,10 +5,13 @@ fn main() {
|
|||
let x = &Baz;
|
||||
let y = &Baz;
|
||||
y.to_owned() == *x;
|
||||
//~^ ERROR: this creates an owned instance just for comparison
|
||||
//~| NOTE: `-D clippy::cmp-owned` implied by `-D warnings`
|
||||
|
||||
let x = &&Baz;
|
||||
let y = &Baz;
|
||||
y.to_owned() == **x;
|
||||
//~^ ERROR: this creates an owned instance just for comparison
|
||||
|
||||
let x = 0u32;
|
||||
let y = U32Wrapper(x);
|
||||
|
@ -20,6 +23,7 @@ struct Foo;
|
|||
impl PartialEq for Foo {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.to_owned() == *other
|
||||
//~^ ERROR: this creates an owned instance just for comparison
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,13 +7,13 @@ LL | y.to_owned() == *x;
|
|||
= note: `-D clippy::cmp-owned` implied by `-D warnings`
|
||||
|
||||
error: this creates an owned instance just for comparison
|
||||
--> $DIR/without_suggestion.rs:11:5
|
||||
--> $DIR/without_suggestion.rs:13:5
|
||||
|
|
||||
LL | y.to_owned() == **x;
|
||||
| ^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating
|
||||
|
||||
error: this creates an owned instance just for comparison
|
||||
--> $DIR/without_suggestion.rs:22:9
|
||||
--> $DIR/without_suggestion.rs:25:9
|
||||
|
|
||||
LL | self.to_owned() == *other
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#[rustfmt::skip]
|
||||
fn main() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (28/25)
|
||||
if true {
|
||||
println!("a");
|
||||
}
|
||||
|
@ -89,6 +90,7 @@ fn main() {
|
|||
|
||||
#[clippy::cognitive_complexity = "1"]
|
||||
fn kaboom() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (7/1)
|
||||
let n = 0;
|
||||
'a: for i in 0..20 {
|
||||
'b: for j in i..20 {
|
||||
|
@ -147,7 +149,9 @@ fn lots_of_short_circuits2() -> bool {
|
|||
|
||||
#[clippy::cognitive_complexity = "1"]
|
||||
fn baa() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (2/1)
|
||||
let x = || match 99 {
|
||||
//~^ ERROR: the function has a cognitive complexity of (2/1)
|
||||
0 => 0,
|
||||
1 => 1,
|
||||
2 => 2,
|
||||
|
@ -165,6 +169,7 @@ fn baa() {
|
|||
|
||||
#[clippy::cognitive_complexity = "1"]
|
||||
fn bar() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (2/1)
|
||||
match 99 {
|
||||
0 => println!("hi"),
|
||||
_ => println!("bye"),
|
||||
|
@ -176,6 +181,7 @@ fn bar() {
|
|||
/// Tests are usually complex but simple at the same time. `clippy::cognitive_complexity` used to
|
||||
/// give lots of false-positives in tests.
|
||||
fn dont_warn_on_tests() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (2/1)
|
||||
match 99 {
|
||||
0 => println!("hi"),
|
||||
_ => println!("bye"),
|
||||
|
@ -184,6 +190,7 @@ fn dont_warn_on_tests() {
|
|||
|
||||
#[clippy::cognitive_complexity = "1"]
|
||||
fn barr() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (2/1)
|
||||
match 99 {
|
||||
0 => println!("hi"),
|
||||
1 => println!("bla"),
|
||||
|
@ -194,6 +201,7 @@ fn barr() {
|
|||
|
||||
#[clippy::cognitive_complexity = "1"]
|
||||
fn barr2() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (3/1)
|
||||
match 99 {
|
||||
0 => println!("hi"),
|
||||
1 => println!("bla"),
|
||||
|
@ -210,6 +218,7 @@ fn barr2() {
|
|||
|
||||
#[clippy::cognitive_complexity = "1"]
|
||||
fn barrr() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (2/1)
|
||||
match 99 {
|
||||
0 => println!("hi"),
|
||||
1 => panic!("bla"),
|
||||
|
@ -220,6 +229,7 @@ fn barrr() {
|
|||
|
||||
#[clippy::cognitive_complexity = "1"]
|
||||
fn barrr2() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (3/1)
|
||||
match 99 {
|
||||
0 => println!("hi"),
|
||||
1 => panic!("bla"),
|
||||
|
@ -236,6 +246,7 @@ fn barrr2() {
|
|||
|
||||
#[clippy::cognitive_complexity = "1"]
|
||||
fn barrrr() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (2/1)
|
||||
match 99 {
|
||||
0 => println!("hi"),
|
||||
1 => println!("bla"),
|
||||
|
@ -246,6 +257,7 @@ fn barrrr() {
|
|||
|
||||
#[clippy::cognitive_complexity = "1"]
|
||||
fn barrrr2() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (3/1)
|
||||
match 99 {
|
||||
0 => println!("hi"),
|
||||
1 => println!("bla"),
|
||||
|
@ -262,6 +274,7 @@ fn barrrr2() {
|
|||
|
||||
#[clippy::cognitive_complexity = "1"]
|
||||
fn cake() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (2/1)
|
||||
if 4 == 5 {
|
||||
println!("yea");
|
||||
} else {
|
||||
|
@ -272,6 +285,7 @@ fn cake() {
|
|||
|
||||
#[clippy::cognitive_complexity = "1"]
|
||||
pub fn read_file(input_path: &str) -> String {
|
||||
//~^ ERROR: the function has a cognitive complexity of (4/1)
|
||||
use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::Path;
|
||||
|
@ -303,6 +317,7 @@ enum Void {}
|
|||
|
||||
#[clippy::cognitive_complexity = "1"]
|
||||
fn void(void: Void) {
|
||||
//~^ ERROR: the function has a cognitive complexity of (2/1)
|
||||
if true {
|
||||
match void {}
|
||||
}
|
||||
|
@ -354,6 +369,7 @@ fn early() -> Result<i32, &'static str> {
|
|||
#[rustfmt::skip]
|
||||
#[clippy::cognitive_complexity = "1"]
|
||||
fn early_ret() -> i32 {
|
||||
//~^ ERROR: the function has a cognitive complexity of (8/1)
|
||||
let a = if true { 42 } else { return 0; };
|
||||
let a = if a < 99 { 42 } else { return 0; };
|
||||
let a = if a < 99 { 42 } else { return 0; };
|
||||
|
@ -375,6 +391,7 @@ fn early_ret() -> i32 {
|
|||
#[clippy::cognitive_complexity = "1"]
|
||||
fn closures() {
|
||||
let x = |a: i32, b: i32| -> i32 {
|
||||
//~^ ERROR: the function has a cognitive complexity of (2/1)
|
||||
if true {
|
||||
println!("moo");
|
||||
}
|
||||
|
@ -388,6 +405,7 @@ struct Moo;
|
|||
#[clippy::cognitive_complexity = "1"]
|
||||
impl Moo {
|
||||
fn moo(&self) {
|
||||
//~^ ERROR: the function has a cognitive complexity of (2/1)
|
||||
if true {
|
||||
println!("moo");
|
||||
}
|
||||
|
@ -397,6 +415,7 @@ impl Moo {
|
|||
#[clippy::cognitive_complexity = "1"]
|
||||
mod issue9300 {
|
||||
async fn a() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (2/1)
|
||||
let a = 0;
|
||||
if a == 0 {}
|
||||
}
|
||||
|
@ -404,6 +423,7 @@ mod issue9300 {
|
|||
pub struct S;
|
||||
impl S {
|
||||
pub async fn async_method() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (2/1)
|
||||
let a = 0;
|
||||
if a == 0 {}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | fn main() {
|
|||
= note: `-D clippy::cognitive-complexity` implied by `-D warnings`
|
||||
|
||||
error: the function has a cognitive complexity of (7/1)
|
||||
--> $DIR/cognitive_complexity.rs:91:4
|
||||
--> $DIR/cognitive_complexity.rs:92:4
|
||||
|
|
||||
LL | fn kaboom() {
|
||||
| ^^^^^^
|
||||
|
@ -16,7 +16,7 @@ LL | fn kaboom() {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (2/1)
|
||||
--> $DIR/cognitive_complexity.rs:149:4
|
||||
--> $DIR/cognitive_complexity.rs:151:4
|
||||
|
|
||||
LL | fn baa() {
|
||||
| ^^^
|
||||
|
@ -24,7 +24,7 @@ LL | fn baa() {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (2/1)
|
||||
--> $DIR/cognitive_complexity.rs:150:13
|
||||
--> $DIR/cognitive_complexity.rs:153:13
|
||||
|
|
||||
LL | let x = || match 99 {
|
||||
| ^^
|
||||
|
@ -32,7 +32,7 @@ LL | let x = || match 99 {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (2/1)
|
||||
--> $DIR/cognitive_complexity.rs:167:4
|
||||
--> $DIR/cognitive_complexity.rs:171:4
|
||||
|
|
||||
LL | fn bar() {
|
||||
| ^^^
|
||||
|
@ -40,7 +40,7 @@ LL | fn bar() {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (2/1)
|
||||
--> $DIR/cognitive_complexity.rs:178:4
|
||||
--> $DIR/cognitive_complexity.rs:183:4
|
||||
|
|
||||
LL | fn dont_warn_on_tests() {
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
@ -48,7 +48,7 @@ LL | fn dont_warn_on_tests() {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (2/1)
|
||||
--> $DIR/cognitive_complexity.rs:186:4
|
||||
--> $DIR/cognitive_complexity.rs:192:4
|
||||
|
|
||||
LL | fn barr() {
|
||||
| ^^^^
|
||||
|
@ -56,7 +56,7 @@ LL | fn barr() {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (3/1)
|
||||
--> $DIR/cognitive_complexity.rs:196:4
|
||||
--> $DIR/cognitive_complexity.rs:203:4
|
||||
|
|
||||
LL | fn barr2() {
|
||||
| ^^^^^
|
||||
|
@ -64,7 +64,7 @@ LL | fn barr2() {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (2/1)
|
||||
--> $DIR/cognitive_complexity.rs:212:4
|
||||
--> $DIR/cognitive_complexity.rs:220:4
|
||||
|
|
||||
LL | fn barrr() {
|
||||
| ^^^^^
|
||||
|
@ -72,7 +72,7 @@ LL | fn barrr() {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (3/1)
|
||||
--> $DIR/cognitive_complexity.rs:222:4
|
||||
--> $DIR/cognitive_complexity.rs:231:4
|
||||
|
|
||||
LL | fn barrr2() {
|
||||
| ^^^^^^
|
||||
|
@ -80,7 +80,7 @@ LL | fn barrr2() {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (2/1)
|
||||
--> $DIR/cognitive_complexity.rs:238:4
|
||||
--> $DIR/cognitive_complexity.rs:248:4
|
||||
|
|
||||
LL | fn barrrr() {
|
||||
| ^^^^^^
|
||||
|
@ -88,7 +88,7 @@ LL | fn barrrr() {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (3/1)
|
||||
--> $DIR/cognitive_complexity.rs:248:4
|
||||
--> $DIR/cognitive_complexity.rs:259:4
|
||||
|
|
||||
LL | fn barrrr2() {
|
||||
| ^^^^^^^
|
||||
|
@ -96,7 +96,7 @@ LL | fn barrrr2() {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (2/1)
|
||||
--> $DIR/cognitive_complexity.rs:264:4
|
||||
--> $DIR/cognitive_complexity.rs:276:4
|
||||
|
|
||||
LL | fn cake() {
|
||||
| ^^^^
|
||||
|
@ -104,7 +104,7 @@ LL | fn cake() {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (4/1)
|
||||
--> $DIR/cognitive_complexity.rs:274:8
|
||||
--> $DIR/cognitive_complexity.rs:287:8
|
||||
|
|
||||
LL | pub fn read_file(input_path: &str) -> String {
|
||||
| ^^^^^^^^^
|
||||
|
@ -112,7 +112,7 @@ LL | pub fn read_file(input_path: &str) -> String {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (2/1)
|
||||
--> $DIR/cognitive_complexity.rs:305:4
|
||||
--> $DIR/cognitive_complexity.rs:319:4
|
||||
|
|
||||
LL | fn void(void: Void) {
|
||||
| ^^^^
|
||||
|
@ -120,7 +120,7 @@ LL | fn void(void: Void) {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (8/1)
|
||||
--> $DIR/cognitive_complexity.rs:356:4
|
||||
--> $DIR/cognitive_complexity.rs:371:4
|
||||
|
|
||||
LL | fn early_ret() -> i32 {
|
||||
| ^^^^^^^^^
|
||||
|
@ -128,7 +128,7 @@ LL | fn early_ret() -> i32 {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (2/1)
|
||||
--> $DIR/cognitive_complexity.rs:377:13
|
||||
--> $DIR/cognitive_complexity.rs:393:13
|
||||
|
|
||||
LL | let x = |a: i32, b: i32| -> i32 {
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
@ -136,7 +136,7 @@ LL | let x = |a: i32, b: i32| -> i32 {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (2/1)
|
||||
--> $DIR/cognitive_complexity.rs:390:8
|
||||
--> $DIR/cognitive_complexity.rs:407:8
|
||||
|
|
||||
LL | fn moo(&self) {
|
||||
| ^^^
|
||||
|
@ -144,7 +144,7 @@ LL | fn moo(&self) {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (2/1)
|
||||
--> $DIR/cognitive_complexity.rs:399:14
|
||||
--> $DIR/cognitive_complexity.rs:417:14
|
||||
|
|
||||
LL | async fn a() {
|
||||
| ^
|
||||
|
@ -152,7 +152,7 @@ LL | async fn a() {
|
|||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: the function has a cognitive complexity of (2/1)
|
||||
--> $DIR/cognitive_complexity.rs:406:22
|
||||
--> $DIR/cognitive_complexity.rs:425:22
|
||||
|
|
||||
LL | pub async fn async_method() {
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
|
@ -7,6 +7,7 @@ fn main() {
|
|||
|
||||
#[clippy::cognitive_complexity = "0"]
|
||||
fn kaboom() {
|
||||
//~^ ERROR: the function has a cognitive complexity of (3/0)
|
||||
if 42 == 43 {
|
||||
panic!();
|
||||
} else if "cake" == "lie" {
|
||||
|
|
|
@ -11,6 +11,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
// match without block
|
||||
match res_opt {
|
||||
Ok(val) => match val {
|
||||
//~^ ERROR: this `match` can be collapsed into the outer `match`
|
||||
Some(n) => foo(n),
|
||||
_ => return,
|
||||
},
|
||||
|
@ -20,6 +21,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
// match with block
|
||||
match res_opt {
|
||||
Ok(val) => match val {
|
||||
//~^ ERROR: this `match` can be collapsed into the outer `match`
|
||||
Some(n) => foo(n),
|
||||
_ => return,
|
||||
},
|
||||
|
@ -29,6 +31,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
// if let, if let
|
||||
if let Ok(val) = res_opt {
|
||||
if let Some(n) = val {
|
||||
//~^ ERROR: this `if let` can be collapsed into the outer `if let`
|
||||
take(n);
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +39,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
// if let else, if let else
|
||||
if let Ok(val) = res_opt {
|
||||
if let Some(n) = val {
|
||||
//~^ ERROR: this `if let` can be collapsed into the outer `if let`
|
||||
take(n);
|
||||
} else {
|
||||
return;
|
||||
|
@ -47,6 +51,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
// if let, match
|
||||
if let Ok(val) = res_opt {
|
||||
match val {
|
||||
//~^ ERROR: this `match` can be collapsed into the outer `if let`
|
||||
Some(n) => foo(n),
|
||||
_ => (),
|
||||
}
|
||||
|
@ -56,6 +61,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
match res_opt {
|
||||
Ok(val) => {
|
||||
if let Some(n) = val {
|
||||
//~^ ERROR: this `if let` can be collapsed into the outer `match`
|
||||
take(n);
|
||||
}
|
||||
},
|
||||
|
@ -65,6 +71,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
// if let else, match
|
||||
if let Ok(val) = res_opt {
|
||||
match val {
|
||||
//~^ ERROR: this `match` can be collapsed into the outer `if let`
|
||||
Some(n) => foo(n),
|
||||
_ => return,
|
||||
}
|
||||
|
@ -76,6 +83,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
match res_opt {
|
||||
Ok(val) => {
|
||||
if let Some(n) = val {
|
||||
//~^ ERROR: this `if let` can be collapsed into the outer `match`
|
||||
take(n);
|
||||
} else {
|
||||
return;
|
||||
|
@ -87,6 +95,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
// None in inner match same as outer wild branch
|
||||
match res_opt {
|
||||
Ok(val) => match val {
|
||||
//~^ ERROR: this `match` can be collapsed into the outer `match`
|
||||
Some(n) => foo(n),
|
||||
None => return,
|
||||
},
|
||||
|
@ -96,6 +105,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
// None in outer match same as inner wild branch
|
||||
match opt_opt {
|
||||
Some(val) => match val {
|
||||
//~^ ERROR: this `match` can be collapsed into the outer `match`
|
||||
Some(n) => foo(n),
|
||||
_ => return,
|
||||
},
|
||||
|
@ -261,6 +271,7 @@ pub enum Issue9647 {
|
|||
pub fn test_1(x: Issue9647) {
|
||||
if let Issue9647::A { a, .. } = x {
|
||||
if let Some(u) = a {
|
||||
//~^ ERROR: this `if let` can be collapsed into the outer `if let`
|
||||
println!("{u:?}")
|
||||
}
|
||||
}
|
||||
|
@ -269,6 +280,7 @@ pub fn test_1(x: Issue9647) {
|
|||
pub fn test_2(x: Issue9647) {
|
||||
if let Issue9647::A { a: Some(a), .. } = x {
|
||||
if let Some(u) = a {
|
||||
//~^ ERROR: this `if let` can be collapsed into the outer `if let`
|
||||
println!("{u}")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ error: this `match` can be collapsed into the outer `match`
|
|||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ____________________^
|
||||
LL | |
|
||||
LL | | Some(n) => foo(n),
|
||||
LL | | _ => return,
|
||||
LL | | },
|
||||
|
@ -13,38 +14,42 @@ help: the outer pattern can be modified to include the inner pattern
|
|||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ^^^ replace this binding
|
||||
LL |
|
||||
LL | Some(n) => foo(n),
|
||||
| ^^^^^^^ with this pattern
|
||||
= note: `-D clippy::collapsible-match` implied by `-D warnings`
|
||||
|
||||
error: this `match` can be collapsed into the outer `match`
|
||||
--> $DIR/collapsible_match.rs:22:20
|
||||
--> $DIR/collapsible_match.rs:23:20
|
||||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ____________________^
|
||||
LL | |
|
||||
LL | | Some(n) => foo(n),
|
||||
LL | | _ => return,
|
||||
LL | | },
|
||||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match.rs:22:12
|
||||
--> $DIR/collapsible_match.rs:23:12
|
||||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ^^^ replace this binding
|
||||
LL |
|
||||
LL | Some(n) => foo(n),
|
||||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `if let` can be collapsed into the outer `if let`
|
||||
--> $DIR/collapsible_match.rs:31:9
|
||||
--> $DIR/collapsible_match.rs:33:9
|
||||
|
|
||||
LL | / if let Some(n) = val {
|
||||
LL | |
|
||||
LL | | take(n);
|
||||
LL | | }
|
||||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match.rs:30:15
|
||||
--> $DIR/collapsible_match.rs:32:15
|
||||
|
|
||||
LL | if let Ok(val) = res_opt {
|
||||
| ^^^ replace this binding
|
||||
|
@ -52,9 +57,10 @@ LL | if let Some(n) = val {
|
|||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `if let` can be collapsed into the outer `if let`
|
||||
--> $DIR/collapsible_match.rs:38:9
|
||||
--> $DIR/collapsible_match.rs:41:9
|
||||
|
|
||||
LL | / if let Some(n) = val {
|
||||
LL | |
|
||||
LL | | take(n);
|
||||
LL | | } else {
|
||||
LL | | return;
|
||||
|
@ -62,7 +68,7 @@ LL | | }
|
|||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match.rs:37:15
|
||||
--> $DIR/collapsible_match.rs:40:15
|
||||
|
|
||||
LL | if let Ok(val) = res_opt {
|
||||
| ^^^ replace this binding
|
||||
|
@ -70,33 +76,35 @@ LL | if let Some(n) = val {
|
|||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `match` can be collapsed into the outer `if let`
|
||||
--> $DIR/collapsible_match.rs:49:9
|
||||
--> $DIR/collapsible_match.rs:53:9
|
||||
|
|
||||
LL | / match val {
|
||||
LL | |
|
||||
LL | | Some(n) => foo(n),
|
||||
LL | | _ => (),
|
||||
LL | | }
|
||||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match.rs:48:15
|
||||
--> $DIR/collapsible_match.rs:52:15
|
||||
|
|
||||
LL | if let Ok(val) = res_opt {
|
||||
| ^^^ replace this binding
|
||||
LL | match val {
|
||||
...
|
||||
LL | Some(n) => foo(n),
|
||||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `if let` can be collapsed into the outer `match`
|
||||
--> $DIR/collapsible_match.rs:58:13
|
||||
--> $DIR/collapsible_match.rs:63:13
|
||||
|
|
||||
LL | / if let Some(n) = val {
|
||||
LL | |
|
||||
LL | | take(n);
|
||||
LL | | }
|
||||
| |_____________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match.rs:57:12
|
||||
--> $DIR/collapsible_match.rs:62:12
|
||||
|
|
||||
LL | Ok(val) => {
|
||||
| ^^^ replace this binding
|
||||
|
@ -104,27 +112,29 @@ LL | if let Some(n) = val {
|
|||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `match` can be collapsed into the outer `if let`
|
||||
--> $DIR/collapsible_match.rs:67:9
|
||||
--> $DIR/collapsible_match.rs:73:9
|
||||
|
|
||||
LL | / match val {
|
||||
LL | |
|
||||
LL | | Some(n) => foo(n),
|
||||
LL | | _ => return,
|
||||
LL | | }
|
||||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match.rs:66:15
|
||||
--> $DIR/collapsible_match.rs:72:15
|
||||
|
|
||||
LL | if let Ok(val) = res_opt {
|
||||
| ^^^ replace this binding
|
||||
LL | match val {
|
||||
...
|
||||
LL | Some(n) => foo(n),
|
||||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `if let` can be collapsed into the outer `match`
|
||||
--> $DIR/collapsible_match.rs:78:13
|
||||
--> $DIR/collapsible_match.rs:85:13
|
||||
|
|
||||
LL | / if let Some(n) = val {
|
||||
LL | |
|
||||
LL | | take(n);
|
||||
LL | | } else {
|
||||
LL | | return;
|
||||
|
@ -132,7 +142,7 @@ LL | | }
|
|||
| |_____________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match.rs:77:12
|
||||
--> $DIR/collapsible_match.rs:84:12
|
||||
|
|
||||
LL | Ok(val) => {
|
||||
| ^^^ replace this binding
|
||||
|
@ -140,51 +150,56 @@ LL | if let Some(n) = val {
|
|||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `match` can be collapsed into the outer `match`
|
||||
--> $DIR/collapsible_match.rs:89:20
|
||||
--> $DIR/collapsible_match.rs:97:20
|
||||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ____________________^
|
||||
LL | |
|
||||
LL | | Some(n) => foo(n),
|
||||
LL | | None => return,
|
||||
LL | | },
|
||||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match.rs:89:12
|
||||
--> $DIR/collapsible_match.rs:97:12
|
||||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ^^^ replace this binding
|
||||
LL |
|
||||
LL | Some(n) => foo(n),
|
||||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `match` can be collapsed into the outer `match`
|
||||
--> $DIR/collapsible_match.rs:98:22
|
||||
--> $DIR/collapsible_match.rs:107:22
|
||||
|
|
||||
LL | Some(val) => match val {
|
||||
| ______________________^
|
||||
LL | |
|
||||
LL | | Some(n) => foo(n),
|
||||
LL | | _ => return,
|
||||
LL | | },
|
||||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match.rs:98:14
|
||||
--> $DIR/collapsible_match.rs:107:14
|
||||
|
|
||||
LL | Some(val) => match val {
|
||||
| ^^^ replace this binding
|
||||
LL |
|
||||
LL | Some(n) => foo(n),
|
||||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `if let` can be collapsed into the outer `if let`
|
||||
--> $DIR/collapsible_match.rs:263:9
|
||||
--> $DIR/collapsible_match.rs:273:9
|
||||
|
|
||||
LL | / if let Some(u) = a {
|
||||
LL | |
|
||||
LL | | println!("{u:?}")
|
||||
LL | | }
|
||||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match.rs:262:27
|
||||
--> $DIR/collapsible_match.rs:272:27
|
||||
|
|
||||
LL | if let Issue9647::A { a, .. } = x {
|
||||
| ^ replace this binding
|
||||
|
@ -192,15 +207,16 @@ LL | if let Some(u) = a {
|
|||
| ^^^^^^^ with this pattern, prefixed by a:
|
||||
|
||||
error: this `if let` can be collapsed into the outer `if let`
|
||||
--> $DIR/collapsible_match.rs:271:9
|
||||
--> $DIR/collapsible_match.rs:282:9
|
||||
|
|
||||
LL | / if let Some(u) = a {
|
||||
LL | |
|
||||
LL | | println!("{u}")
|
||||
LL | | }
|
||||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match.rs:270:35
|
||||
--> $DIR/collapsible_match.rs:281:35
|
||||
|
|
||||
LL | if let Issue9647::A { a: Some(a), .. } = x {
|
||||
| ^ replace this binding
|
||||
|
|
|
@ -11,6 +11,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
{
|
||||
match res_opt {
|
||||
Ok(val) if make() => match val {
|
||||
//~^ ERROR: this `match` can be collapsed into the outer `match`
|
||||
Some(n) => foo(n),
|
||||
_ => return,
|
||||
},
|
||||
|
@ -18,6 +19,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
}
|
||||
match res_opt {
|
||||
Ok(val) => match val {
|
||||
//~^ ERROR: this `match` can be collapsed into the outer `match`
|
||||
Some(n) => foo(n),
|
||||
_ => return,
|
||||
},
|
||||
|
@ -49,6 +51,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
// deref reference value
|
||||
match Some(&[1]) {
|
||||
Some(s) => match *s {
|
||||
//~^ ERROR: this `match` can be collapsed into the outer `match`
|
||||
[n] => foo(n),
|
||||
_ => (),
|
||||
},
|
||||
|
@ -58,6 +61,7 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
|
|||
// ref pattern and deref
|
||||
match Some(&[1]) {
|
||||
Some(ref s) => match s {
|
||||
//~^ ERROR: this `match` can be collapsed into the outer `match`
|
||||
[n] => foo(n),
|
||||
_ => (),
|
||||
},
|
||||
|
|
|
@ -3,6 +3,7 @@ error: this `match` can be collapsed into the outer `match`
|
|||
|
|
||||
LL | Ok(val) if make() => match val {
|
||||
| __________________________________^
|
||||
LL | |
|
||||
LL | | Some(n) => foo(n),
|
||||
LL | | _ => return,
|
||||
LL | | },
|
||||
|
@ -13,30 +14,33 @@ help: the outer pattern can be modified to include the inner pattern
|
|||
|
|
||||
LL | Ok(val) if make() => match val {
|
||||
| ^^^ replace this binding
|
||||
LL |
|
||||
LL | Some(n) => foo(n),
|
||||
| ^^^^^^^ with this pattern
|
||||
= note: `-D clippy::collapsible-match` implied by `-D warnings`
|
||||
|
||||
error: this `match` can be collapsed into the outer `match`
|
||||
--> $DIR/collapsible_match2.rs:20:24
|
||||
--> $DIR/collapsible_match2.rs:21:24
|
||||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ________________________^
|
||||
LL | |
|
||||
LL | | Some(n) => foo(n),
|
||||
LL | | _ => return,
|
||||
LL | | },
|
||||
| |_____________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match2.rs:20:16
|
||||
--> $DIR/collapsible_match2.rs:21:16
|
||||
|
|
||||
LL | Ok(val) => match val {
|
||||
| ^^^ replace this binding
|
||||
LL |
|
||||
LL | Some(n) => foo(n),
|
||||
| ^^^^^^^ with this pattern
|
||||
|
||||
error: this `match` can be collapsed into the outer `match`
|
||||
--> $DIR/collapsible_match2.rs:34:29
|
||||
--> $DIR/collapsible_match2.rs:36:29
|
||||
|
|
||||
LL | $pat => match $e {
|
||||
| _____________________________^
|
||||
|
@ -49,7 +53,7 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
|
|||
| ------------------------------------------------ in this macro invocation
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match2.rs:46:28
|
||||
--> $DIR/collapsible_match2.rs:48:28
|
||||
|
|
||||
LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
|
||||
| ^^^ ^^^^^^^ with this pattern
|
||||
|
@ -58,38 +62,42 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
|
|||
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: this `match` can be collapsed into the outer `match`
|
||||
--> $DIR/collapsible_match2.rs:51:20
|
||||
--> $DIR/collapsible_match2.rs:53:20
|
||||
|
|
||||
LL | Some(s) => match *s {
|
||||
| ____________________^
|
||||
LL | |
|
||||
LL | | [n] => foo(n),
|
||||
LL | | _ => (),
|
||||
LL | | },
|
||||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match2.rs:51:14
|
||||
--> $DIR/collapsible_match2.rs:53:14
|
||||
|
|
||||
LL | Some(s) => match *s {
|
||||
| ^ replace this binding
|
||||
LL |
|
||||
LL | [n] => foo(n),
|
||||
| ^^^ with this pattern
|
||||
|
||||
error: this `match` can be collapsed into the outer `match`
|
||||
--> $DIR/collapsible_match2.rs:60:24
|
||||
--> $DIR/collapsible_match2.rs:63:24
|
||||
|
|
||||
LL | Some(ref s) => match s {
|
||||
| ________________________^
|
||||
LL | |
|
||||
LL | | [n] => foo(n),
|
||||
LL | | _ => (),
|
||||
LL | | },
|
||||
| |_________^
|
||||
|
|
||||
help: the outer pattern can be modified to include the inner pattern
|
||||
--> $DIR/collapsible_match2.rs:60:14
|
||||
--> $DIR/collapsible_match2.rs:63:14
|
||||
|
|
||||
LL | Some(ref s) => match s {
|
||||
| ^^^^^ replace this binding
|
||||
LL |
|
||||
LL | [n] => foo(n),
|
||||
| ^^^ with this pattern
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ fn no_access_at_all() {
|
|||
fn write_without_read() {
|
||||
// The main use case for `collection_is_never_read`.
|
||||
let mut x = HashMap::new();
|
||||
//~^ ERROR: collection is never read
|
||||
//~| NOTE: `-D clippy::collection-is-never-read` implied by `-D warnings`
|
||||
x.insert(1, 2);
|
||||
}
|
||||
|
||||
|
@ -58,6 +60,7 @@ fn read_in_closure() {
|
|||
|
||||
fn write_in_closure() {
|
||||
let mut x = vec![1, 2, 3];
|
||||
//~^ ERROR: collection is never read
|
||||
let _ = || {
|
||||
x.push(4);
|
||||
};
|
||||
|
@ -73,11 +76,13 @@ fn shadowing_1() {
|
|||
let x = HashMap::<usize, usize>::new(); // Ok
|
||||
let _ = x.len();
|
||||
let mut x = HashMap::new();
|
||||
//~^ ERROR: collection is never read
|
||||
x.insert(1, 2);
|
||||
}
|
||||
|
||||
fn shadowing_2() {
|
||||
let mut x = HashMap::new();
|
||||
//~^ ERROR: collection is never read
|
||||
x.insert(1, 2);
|
||||
let x = HashMap::<usize, usize>::new(); // Ok
|
||||
let _ = x.len();
|
||||
|
@ -86,18 +91,21 @@ fn shadowing_2() {
|
|||
#[allow(clippy::let_unit_value)]
|
||||
fn fake_read_1() {
|
||||
let mut x = vec![1, 2, 3];
|
||||
//~^ ERROR: collection is never read
|
||||
x.reverse();
|
||||
let _: () = x.clear();
|
||||
}
|
||||
|
||||
fn fake_read_2() {
|
||||
let mut x = vec![1, 2, 3];
|
||||
//~^ ERROR: collection is never read
|
||||
x.reverse();
|
||||
println!("{:?}", x.push(5));
|
||||
}
|
||||
|
||||
fn assignment() {
|
||||
let mut x = vec![1, 2, 3];
|
||||
//~^ ERROR: collection is never read
|
||||
let y = vec![4, 5, 6]; // Ok
|
||||
x = y;
|
||||
}
|
||||
|
@ -105,6 +113,7 @@ fn assignment() {
|
|||
#[allow(clippy::self_assignment)]
|
||||
fn self_assignment() {
|
||||
let mut x = vec![1, 2, 3];
|
||||
//~^ ERROR: collection is never read
|
||||
x = x;
|
||||
}
|
||||
|
||||
|
@ -122,6 +131,7 @@ fn method_argument_but_not_target() {
|
|||
|
||||
fn insert_is_not_a_read() {
|
||||
let mut x = HashSet::new();
|
||||
//~^ ERROR: collection is never read
|
||||
x.insert(5);
|
||||
}
|
||||
|
||||
|
@ -136,6 +146,7 @@ fn not_read_if_return_value_not_used() {
|
|||
// `is_empty` does not modify the set, so it's a query. But since the return value is not used, the
|
||||
// lint does not consider it a read here.
|
||||
let x = vec![1, 2, 3];
|
||||
//~^ ERROR: collection is never read
|
||||
x.is_empty();
|
||||
}
|
||||
|
||||
|
@ -171,33 +182,43 @@ fn function_argument() {
|
|||
|
||||
fn supported_types() {
|
||||
let mut x = std::collections::BTreeMap::new();
|
||||
//~^ ERROR: collection is never read
|
||||
x.insert(true, 1);
|
||||
|
||||
let mut x = std::collections::BTreeSet::new();
|
||||
//~^ ERROR: collection is never read
|
||||
x.insert(1);
|
||||
|
||||
let mut x = std::collections::BinaryHeap::new();
|
||||
//~^ ERROR: collection is never read
|
||||
x.push(1);
|
||||
|
||||
let mut x = std::collections::HashMap::new();
|
||||
//~^ ERROR: collection is never read
|
||||
x.insert(1, 2);
|
||||
|
||||
let mut x = std::collections::HashSet::new();
|
||||
//~^ ERROR: collection is never read
|
||||
x.insert(1);
|
||||
|
||||
let mut x = std::collections::LinkedList::new();
|
||||
//~^ ERROR: collection is never read
|
||||
x.push_front(1);
|
||||
|
||||
let mut x = Some(true);
|
||||
//~^ ERROR: collection is never read
|
||||
x.insert(false);
|
||||
|
||||
let mut x = String::from("hello");
|
||||
//~^ ERROR: collection is never read
|
||||
x.push('!');
|
||||
|
||||
let mut x = Vec::new();
|
||||
//~^ ERROR: collection is never read
|
||||
x.clear();
|
||||
x.push(1);
|
||||
|
||||
let mut x = std::collections::VecDeque::new();
|
||||
//~^ ERROR: collection is never read
|
||||
x.push_front(1);
|
||||
}
|
||||
|
|
|
@ -7,31 +7,25 @@ LL | let mut x = HashMap::new();
|
|||
= note: `-D clippy::collection-is-never-read` implied by `-D warnings`
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:60:5
|
||||
--> $DIR/collection_is_never_read.rs:62:5
|
||||
|
|
||||
LL | let mut x = vec![1, 2, 3];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:75:5
|
||||
--> $DIR/collection_is_never_read.rs:78:5
|
||||
|
|
||||
LL | let mut x = HashMap::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:80:5
|
||||
--> $DIR/collection_is_never_read.rs:84:5
|
||||
|
|
||||
LL | let mut x = HashMap::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:88:5
|
||||
|
|
||||
LL | let mut x = vec![1, 2, 3];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:94:5
|
||||
--> $DIR/collection_is_never_read.rs:93:5
|
||||
|
|
||||
LL | let mut x = vec![1, 2, 3];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -49,73 +43,79 @@ LL | let mut x = vec![1, 2, 3];
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:124:5
|
||||
--> $DIR/collection_is_never_read.rs:115:5
|
||||
|
|
||||
LL | let mut x = vec![1, 2, 3];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:133:5
|
||||
|
|
||||
LL | let mut x = HashSet::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:138:5
|
||||
--> $DIR/collection_is_never_read.rs:148:5
|
||||
|
|
||||
LL | let x = vec![1, 2, 3];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:173:5
|
||||
--> $DIR/collection_is_never_read.rs:184:5
|
||||
|
|
||||
LL | let mut x = std::collections::BTreeMap::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:176:5
|
||||
--> $DIR/collection_is_never_read.rs:188:5
|
||||
|
|
||||
LL | let mut x = std::collections::BTreeSet::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:179:5
|
||||
--> $DIR/collection_is_never_read.rs:192:5
|
||||
|
|
||||
LL | let mut x = std::collections::BinaryHeap::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:182:5
|
||||
--> $DIR/collection_is_never_read.rs:196:5
|
||||
|
|
||||
LL | let mut x = std::collections::HashMap::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:185:5
|
||||
--> $DIR/collection_is_never_read.rs:200:5
|
||||
|
|
||||
LL | let mut x = std::collections::HashSet::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:188:5
|
||||
--> $DIR/collection_is_never_read.rs:204:5
|
||||
|
|
||||
LL | let mut x = std::collections::LinkedList::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:191:5
|
||||
--> $DIR/collection_is_never_read.rs:208:5
|
||||
|
|
||||
LL | let mut x = Some(true);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:194:5
|
||||
--> $DIR/collection_is_never_read.rs:212:5
|
||||
|
|
||||
LL | let mut x = String::from("hello");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:197:5
|
||||
--> $DIR/collection_is_never_read.rs:216:5
|
||||
|
|
||||
LL | let mut x = Vec::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:201:5
|
||||
--> $DIR/collection_is_never_read.rs:221:5
|
||||
|
|
||||
LL | let mut x = std::collections::VecDeque::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -12,6 +12,7 @@ fn f(x: u8, y: u8, z: u8) {
|
|||
}
|
||||
|
||||
if x > y {
|
||||
//~^ ERROR: `if` chain can be rewritten with `match`
|
||||
a()
|
||||
} else if x < y {
|
||||
b()
|
||||
|
@ -25,6 +26,7 @@ fn f(x: u8, y: u8, z: u8) {
|
|||
}
|
||||
|
||||
if x > y {
|
||||
//~^ ERROR: `if` chain can be rewritten with `match`
|
||||
a()
|
||||
} else if x < y {
|
||||
b()
|
||||
|
@ -33,6 +35,7 @@ fn f(x: u8, y: u8, z: u8) {
|
|||
}
|
||||
|
||||
if x > y {
|
||||
//~^ ERROR: `if` chain can be rewritten with `match`
|
||||
a()
|
||||
} else if y > x {
|
||||
b()
|
||||
|
@ -41,6 +44,7 @@ fn f(x: u8, y: u8, z: u8) {
|
|||
}
|
||||
|
||||
if x > 1 {
|
||||
//~^ ERROR: `if` chain can be rewritten with `match`
|
||||
a()
|
||||
} else if x < 1 {
|
||||
b()
|
||||
|
@ -115,12 +119,14 @@ fn g(x: f64, y: f64, z: f64) {
|
|||
|
||||
fn h<T: Ord>(x: T, y: T, z: T) {
|
||||
if x > y {
|
||||
//~^ ERROR: `if` chain can be rewritten with `match`
|
||||
a()
|
||||
} else if x < y {
|
||||
b()
|
||||
}
|
||||
|
||||
if x > y {
|
||||
//~^ ERROR: `if` chain can be rewritten with `match`
|
||||
a()
|
||||
} else if x < y {
|
||||
b()
|
||||
|
@ -129,6 +135,7 @@ fn h<T: Ord>(x: T, y: T, z: T) {
|
|||
}
|
||||
|
||||
if x > y {
|
||||
//~^ ERROR: `if` chain can be rewritten with `match`
|
||||
a()
|
||||
} else if y > x {
|
||||
b()
|
||||
|
|
|
@ -2,6 +2,7 @@ error: `if` chain can be rewritten with `match`
|
|||
--> $DIR/comparison_chain.rs:14:5
|
||||
|
|
||||
LL | / if x > y {
|
||||
LL | |
|
||||
LL | | a()
|
||||
LL | | } else if x < y {
|
||||
LL | | b()
|
||||
|
@ -12,13 +13,13 @@ LL | | }
|
|||
= note: `-D clippy::comparison-chain` implied by `-D warnings`
|
||||
|
||||
error: `if` chain can be rewritten with `match`
|
||||
--> $DIR/comparison_chain.rs:27:5
|
||||
--> $DIR/comparison_chain.rs:28:5
|
||||
|
|
||||
LL | / if x > y {
|
||||
LL | |
|
||||
LL | | a()
|
||||
LL | | } else if x < y {
|
||||
LL | | b()
|
||||
LL | | } else {
|
||||
... |
|
||||
LL | | c()
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
@ -26,13 +27,13 @@ LL | | }
|
|||
= help: consider rewriting the `if` chain to use `cmp` and `match`
|
||||
|
||||
error: `if` chain can be rewritten with `match`
|
||||
--> $DIR/comparison_chain.rs:35:5
|
||||
--> $DIR/comparison_chain.rs:37:5
|
||||
|
|
||||
LL | / if x > y {
|
||||
LL | |
|
||||
LL | | a()
|
||||
LL | | } else if y > x {
|
||||
LL | | b()
|
||||
LL | | } else {
|
||||
... |
|
||||
LL | | c()
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
@ -40,13 +41,13 @@ LL | | }
|
|||
= help: consider rewriting the `if` chain to use `cmp` and `match`
|
||||
|
||||
error: `if` chain can be rewritten with `match`
|
||||
--> $DIR/comparison_chain.rs:43:5
|
||||
--> $DIR/comparison_chain.rs:46:5
|
||||
|
|
||||
LL | / if x > 1 {
|
||||
LL | |
|
||||
LL | | a()
|
||||
LL | | } else if x < 1 {
|
||||
LL | | b()
|
||||
LL | | } else if x == 1 {
|
||||
... |
|
||||
LL | | c()
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
@ -54,9 +55,10 @@ LL | | }
|
|||
= help: consider rewriting the `if` chain to use `cmp` and `match`
|
||||
|
||||
error: `if` chain can be rewritten with `match`
|
||||
--> $DIR/comparison_chain.rs:117:5
|
||||
--> $DIR/comparison_chain.rs:121:5
|
||||
|
|
||||
LL | / if x > y {
|
||||
LL | |
|
||||
LL | | a()
|
||||
LL | | } else if x < y {
|
||||
LL | | b()
|
||||
|
@ -66,13 +68,13 @@ LL | | }
|
|||
= help: consider rewriting the `if` chain to use `cmp` and `match`
|
||||
|
||||
error: `if` chain can be rewritten with `match`
|
||||
--> $DIR/comparison_chain.rs:123:5
|
||||
--> $DIR/comparison_chain.rs:128:5
|
||||
|
|
||||
LL | / if x > y {
|
||||
LL | |
|
||||
LL | | a()
|
||||
LL | | } else if x < y {
|
||||
LL | | b()
|
||||
LL | | } else {
|
||||
... |
|
||||
LL | | c()
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
@ -80,13 +82,13 @@ LL | | }
|
|||
= help: consider rewriting the `if` chain to use `cmp` and `match`
|
||||
|
||||
error: `if` chain can be rewritten with `match`
|
||||
--> $DIR/comparison_chain.rs:131:5
|
||||
--> $DIR/comparison_chain.rs:137:5
|
||||
|
|
||||
LL | / if x > y {
|
||||
LL | |
|
||||
LL | | a()
|
||||
LL | | } else if y > x {
|
||||
LL | | b()
|
||||
LL | | } else {
|
||||
... |
|
||||
LL | | c()
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
|
@ -42,52 +42,96 @@ fn main() {
|
|||
|
||||
status_code >= 400 && status_code < 500; // Correct
|
||||
status_code <= 400 && status_code > 500;
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `400` < `500`, the expression evaluates to false for any value of `st
|
||||
status_code > 500 && status_code < 400;
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `500` > `400`, the expression evaluates to false for any value of `st
|
||||
status_code < 500 && status_code > 500;
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: `status_code` cannot simultaneously be greater than and less than `500`
|
||||
|
||||
// More complex expressions
|
||||
status_code < { 400 } && status_code > { 500 };
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any valu
|
||||
status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR;
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluate
|
||||
status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR;
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to f
|
||||
status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR;
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: `status_code` cannot simultaneously be greater than and less than `STATUS_S
|
||||
|
||||
// Comparing two different types, via the `impl PartialOrd<u16> for Status`
|
||||
status < { 400 } && status > { 500 };
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any valu
|
||||
status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR;
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluate
|
||||
status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR;
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to f
|
||||
status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR;
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: `status` cannot simultaneously be greater than and less than `STATUS_SERVER
|
||||
|
||||
// Yoda conditions
|
||||
500 <= status_code && 600 > status_code; // Correct
|
||||
500 <= status_code && status_code <= 600; // Correct
|
||||
500 >= status_code && 600 < status_code; // Incorrect
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st
|
||||
500 >= status_code && status_code > 600; // Incorrect
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st
|
||||
|
||||
// Yoda conditions, comparing two different types
|
||||
500 <= status && 600 > status; // Correct
|
||||
500 <= status && status <= 600; // Correct
|
||||
500 >= status && 600 < status; // Incorrect
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st
|
||||
500 >= status && status > 600; // Incorrect
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st
|
||||
|
||||
// Expressions where one of the sides has no effect
|
||||
status_code < 200 && status_code <= 299;
|
||||
//~^ ERROR: right-hand side of `&&` operator has no effect
|
||||
status_code > 200 && status_code >= 299;
|
||||
//~^ ERROR: left-hand side of `&&` operator has no effect
|
||||
|
||||
status_code >= 500 && status_code > 500; // Useless left
|
||||
//~^ ERROR: left-hand side of `&&` operator has no effect
|
||||
status_code > 500 && status_code >= 500; // Useless right
|
||||
//~^ ERROR: right-hand side of `&&` operator has no effect
|
||||
status_code <= 500 && status_code < 500; // Useless left
|
||||
//~^ ERROR: left-hand side of `&&` operator has no effect
|
||||
status_code < 500 && status_code <= 500; // Useless right
|
||||
//~^ ERROR: right-hand side of `&&` operator has no effect
|
||||
|
||||
// Other types
|
||||
let name = "Steve";
|
||||
name < "Jennifer" && name > "Shannon";
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `"Jennifer"` < `"Shannon"`, the expression evaluates to false for any
|
||||
|
||||
let numbers = [1, 2];
|
||||
numbers < [3, 4] && numbers > [5, 6];
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `[3, 4]` < `[5, 6]`, the expression evaluates to false for any value
|
||||
|
||||
let letter = 'a';
|
||||
letter < 'b' && letter > 'c';
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `'b'` < `'c'`, the expression evaluates to false for any value of `le
|
||||
|
||||
let area = 42.0;
|
||||
area < std::f32::consts::E && area > std::f32::consts::PI;
|
||||
//~^ ERROR: boolean expression will never evaluate to 'true'
|
||||
//~| NOTE: since `std::f32::consts::E` < `std::f32::consts::PI`, the expression evalua
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | status_code <= 400 && status_code > 500;
|
|||
= note: `-D clippy::impossible-comparisons` implied by `-D warnings`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:45:5
|
||||
--> $DIR/const_comparisons.rs:47:5
|
||||
|
|
||||
LL | status_code > 500 && status_code < 400;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -16,7 +16,7 @@ LL | status_code > 500 && status_code < 400;
|
|||
= note: since `500` > `400`, the expression evaluates to false for any value of `status_code`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:46:5
|
||||
--> $DIR/const_comparisons.rs:50:5
|
||||
|
|
||||
LL | status_code < 500 && status_code > 500;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -24,7 +24,7 @@ LL | status_code < 500 && status_code > 500;
|
|||
= note: `status_code` cannot simultaneously be greater than and less than `500`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:49:5
|
||||
--> $DIR/const_comparisons.rs:55:5
|
||||
|
|
||||
LL | status_code < { 400 } && status_code > { 500 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -32,7 +32,7 @@ LL | status_code < { 400 } && status_code > { 500 };
|
|||
= note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status_code`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:50:5
|
||||
--> $DIR/const_comparisons.rs:58:5
|
||||
|
|
||||
LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -40,7 +40,7 @@ LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR;
|
|||
= note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:51:5
|
||||
--> $DIR/const_comparisons.rs:61:5
|
||||
|
|
||||
LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -48,7 +48,7 @@ LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR;
|
|||
= note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:52:5
|
||||
--> $DIR/const_comparisons.rs:64:5
|
||||
|
|
||||
LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -56,7 +56,7 @@ LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR;
|
|||
= note: `status_code` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:55:5
|
||||
--> $DIR/const_comparisons.rs:69:5
|
||||
|
|
||||
LL | status < { 400 } && status > { 500 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -64,7 +64,7 @@ LL | status < { 400 } && status > { 500 };
|
|||
= note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:56:5
|
||||
--> $DIR/const_comparisons.rs:72:5
|
||||
|
|
||||
LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -72,7 +72,7 @@ LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR;
|
|||
= note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:57:5
|
||||
--> $DIR/const_comparisons.rs:75:5
|
||||
|
|
||||
LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -80,7 +80,7 @@ LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR;
|
|||
= note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:58:5
|
||||
--> $DIR/const_comparisons.rs:78:5
|
||||
|
|
||||
LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -88,7 +88,7 @@ LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR;
|
|||
= note: `status` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:63:5
|
||||
--> $DIR/const_comparisons.rs:85:5
|
||||
|
|
||||
LL | 500 >= status_code && 600 < status_code; // Incorrect
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -96,7 +96,7 @@ LL | 500 >= status_code && 600 < status_code; // Incorrect
|
|||
= note: since `500` < `600`, the expression evaluates to false for any value of `status_code`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:64:5
|
||||
--> $DIR/const_comparisons.rs:88:5
|
||||
|
|
||||
LL | 500 >= status_code && status_code > 600; // Incorrect
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -104,7 +104,7 @@ LL | 500 >= status_code && status_code > 600; // Incorrect
|
|||
= note: since `500` < `600`, the expression evaluates to false for any value of `status_code`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:69:5
|
||||
--> $DIR/const_comparisons.rs:95:5
|
||||
|
|
||||
LL | 500 >= status && 600 < status; // Incorrect
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -112,7 +112,7 @@ LL | 500 >= status && 600 < status; // Incorrect
|
|||
= note: since `500` < `600`, the expression evaluates to false for any value of `status`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:70:5
|
||||
--> $DIR/const_comparisons.rs:98:5
|
||||
|
|
||||
LL | 500 >= status && status > 600; // Incorrect
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -120,80 +120,80 @@ LL | 500 >= status && status > 600; // Incorrect
|
|||
= note: since `500` < `600`, the expression evaluates to false for any value of `status`
|
||||
|
||||
error: right-hand side of `&&` operator has no effect
|
||||
--> $DIR/const_comparisons.rs:73:5
|
||||
--> $DIR/const_comparisons.rs:103:5
|
||||
|
|
||||
LL | status_code < 200 && status_code <= 299;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: `if `status_code < 200` evaluates to true, status_code <= 299` will always evaluate to true as well
|
||||
--> $DIR/const_comparisons.rs:73:23
|
||||
--> $DIR/const_comparisons.rs:103:23
|
||||
|
|
||||
LL | status_code < 200 && status_code <= 299;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: `-D clippy::redundant-comparisons` implied by `-D warnings`
|
||||
|
||||
error: left-hand side of `&&` operator has no effect
|
||||
--> $DIR/const_comparisons.rs:74:5
|
||||
--> $DIR/const_comparisons.rs:105:5
|
||||
|
|
||||
LL | status_code > 200 && status_code >= 299;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: `if `status_code >= 299` evaluates to true, status_code > 200` will always evaluate to true as well
|
||||
--> $DIR/const_comparisons.rs:74:5
|
||||
--> $DIR/const_comparisons.rs:105:5
|
||||
|
|
||||
LL | status_code > 200 && status_code >= 299;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: left-hand side of `&&` operator has no effect
|
||||
--> $DIR/const_comparisons.rs:76:5
|
||||
--> $DIR/const_comparisons.rs:108:5
|
||||
|
|
||||
LL | status_code >= 500 && status_code > 500; // Useless left
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well
|
||||
--> $DIR/const_comparisons.rs:76:5
|
||||
--> $DIR/const_comparisons.rs:108:5
|
||||
|
|
||||
LL | status_code >= 500 && status_code > 500; // Useless left
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: right-hand side of `&&` operator has no effect
|
||||
--> $DIR/const_comparisons.rs:77:5
|
||||
--> $DIR/const_comparisons.rs:110:5
|
||||
|
|
||||
LL | status_code > 500 && status_code >= 500; // Useless right
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well
|
||||
--> $DIR/const_comparisons.rs:77:23
|
||||
--> $DIR/const_comparisons.rs:110:23
|
||||
|
|
||||
LL | status_code > 500 && status_code >= 500; // Useless right
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: left-hand side of `&&` operator has no effect
|
||||
--> $DIR/const_comparisons.rs:78:5
|
||||
--> $DIR/const_comparisons.rs:112:5
|
||||
|
|
||||
LL | status_code <= 500 && status_code < 500; // Useless left
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well
|
||||
--> $DIR/const_comparisons.rs:78:5
|
||||
--> $DIR/const_comparisons.rs:112:5
|
||||
|
|
||||
LL | status_code <= 500 && status_code < 500; // Useless left
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: right-hand side of `&&` operator has no effect
|
||||
--> $DIR/const_comparisons.rs:79:5
|
||||
--> $DIR/const_comparisons.rs:114:5
|
||||
|
|
||||
LL | status_code < 500 && status_code <= 500; // Useless right
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well
|
||||
--> $DIR/const_comparisons.rs:79:23
|
||||
--> $DIR/const_comparisons.rs:114:23
|
||||
|
|
||||
LL | status_code < 500 && status_code <= 500; // Useless right
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:83:5
|
||||
--> $DIR/const_comparisons.rs:119:5
|
||||
|
|
||||
LL | name < "Jennifer" && name > "Shannon";
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -201,7 +201,7 @@ LL | name < "Jennifer" && name > "Shannon";
|
|||
= note: since `"Jennifer"` < `"Shannon"`, the expression evaluates to false for any value of `name`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:86:5
|
||||
--> $DIR/const_comparisons.rs:124:5
|
||||
|
|
||||
LL | numbers < [3, 4] && numbers > [5, 6];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -209,7 +209,7 @@ LL | numbers < [3, 4] && numbers > [5, 6];
|
|||
= note: since `[3, 4]` < `[5, 6]`, the expression evaluates to false for any value of `numbers`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:89:5
|
||||
--> $DIR/const_comparisons.rs:129:5
|
||||
|
|
||||
LL | letter < 'b' && letter > 'c';
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -217,7 +217,7 @@ LL | letter < 'b' && letter > 'c';
|
|||
= note: since `'b'` < `'c'`, the expression evaluates to false for any value of `letter`
|
||||
|
||||
error: boolean expression will never evaluate to 'true'
|
||||
--> $DIR/const_comparisons.rs:92:5
|
||||
--> $DIR/const_comparisons.rs:134:5
|
||||
|
|
||||
LL | area < std::f32::consts::E && area > std::f32::consts::PI;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
struct Countdown(u8);
|
||||
|
||||
impl Iterator for Countdown {
|
||||
//~^ ERROR: you are implementing `Iterator` on a `Copy` type
|
||||
//~| NOTE: consider implementing `IntoIterator` instead
|
||||
type Item = u8;
|
||||
|
||||
fn next(&mut self) -> Option<u8> {
|
||||
|
|
|
@ -2,9 +2,9 @@ error: you are implementing `Iterator` on a `Copy` type
|
|||
--> $DIR/copy_iterator.rs:6:1
|
||||
|
|
||||
LL | / impl Iterator for Countdown {
|
||||
LL | | type Item = u8;
|
||||
LL | |
|
||||
LL | | fn next(&mut self) -> Option<u8> {
|
||||
LL | |
|
||||
LL | | type Item = u8;
|
||||
... |
|
||||
LL | | }
|
||||
LL | | }
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#![warn(clippy::unreadable_literal)]
|
||||
fn f2() -> impl Sized { && 3.14159265358979323846E }
|
||||
//@no-rustfix
|
||||
fn f2() -> impl Sized { && 3.14159265358979323846E }
|
||||
//~^ ERROR: expected at least one digit in exponent
|
||||
//~| ERROR: long literal lacking separators
|
||||
//~| NOTE: `-D clippy::unreadable-literal` implied by `-D warnings`
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
error: expected at least one digit in exponent
|
||||
--> $DIR/ice-10912.rs:2:28
|
||||
--> $DIR/ice-10912.rs:3:28
|
||||
|
|
||||
LL | fn f2() -> impl Sized { && 3.14159265358979323846E }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/ice-10912.rs:2:28
|
||||
--> $DIR/ice-10912.rs:3:28
|
||||
|
|
||||
LL | fn f2() -> impl Sized { && 3.14159265358979323846E }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider: `3.141_592_653_589_793_238_46`
|
||||
|
|
|
@ -13,6 +13,8 @@ pub struct Foo;
|
|||
#[allow(clippy::implicit_hasher)]
|
||||
// This should not cause a "cannot relate bound region" ICE.
|
||||
pub fn add_barfoos_to_foos(bars: &HashSet<&Bar>) {
|
||||
//~^ ERROR: the following explicit lifetimes could be elided: 'a
|
||||
//~| NOTE: `-D clippy::needless-lifetimes` implied by `-D warnings`
|
||||
let mut foos = HashSet::new();
|
||||
foos.extend(bars.iter().map(|b| &b.foo));
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ pub struct Foo;
|
|||
#[allow(clippy::implicit_hasher)]
|
||||
// This should not cause a "cannot relate bound region" ICE.
|
||||
pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) {
|
||||
//~^ ERROR: the following explicit lifetimes could be elided: 'a
|
||||
//~| NOTE: `-D clippy::needless-lifetimes` implied by `-D warnings`
|
||||
let mut foos = HashSet::new();
|
||||
foos.extend(bars.iter().map(|b| &b.foo));
|
||||
}
|
||||
|
|
|
@ -3,10 +3,13 @@ fn main() {}
|
|||
fn no_panic<T>(slice: &[T]) {
|
||||
let mut iter = slice.iter();
|
||||
loop {
|
||||
//~^ ERROR: this loop could be written as a `while let` loop
|
||||
//~| NOTE: `-D clippy::while-let-loop` implied by `-D warnings`
|
||||
let _ = match iter.next() {
|
||||
Some(ele) => ele,
|
||||
None => break,
|
||||
};
|
||||
loop {}
|
||||
//~^ ERROR: empty `loop {}` wastes CPU cycles
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,18 +2,18 @@ error: this loop could be written as a `while let` loop
|
|||
--> $DIR/ice-360.rs:5:5
|
||||
|
|
||||
LL | / loop {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | let _ = match iter.next() {
|
||||
LL | | Some(ele) => ele,
|
||||
LL | | None => break,
|
||||
LL | | };
|
||||
LL | | loop {}
|
||||
... |
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_____^ help: try: `while let Some(ele) = iter.next() { .. }`
|
||||
|
|
||||
= note: `-D clippy::while-let-loop` implied by `-D warnings`
|
||||
|
||||
error: empty `loop {}` wastes CPU cycles
|
||||
--> $DIR/ice-360.rs:10:9
|
||||
--> $DIR/ice-360.rs:12:9
|
||||
|
|
||||
LL | loop {}
|
||||
| ^^^^^^^
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::collections::HashSet;
|
|||
fn main() {}
|
||||
|
||||
pub fn ice_3717<S: ::std::hash::BuildHasher + Default>(_: &HashSet<usize, S>) {
|
||||
//~^ ERROR: parameter of type `HashSet` should be generalized over different hashers
|
||||
let _ = [0u8; 0];
|
||||
let _: HashSet<usize> = HashSet::default();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::collections::HashSet;
|
|||
fn main() {}
|
||||
|
||||
pub fn ice_3717(_: &HashSet<usize>) {
|
||||
//~^ ERROR: parameter of type `HashSet` should be generalized over different hashers
|
||||
let _ = [0u8; 0];
|
||||
let _: HashSet<usize> = HashSet::new();
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
fn main() {
|
||||
1x;
|
||||
//~^ ERROR: invalid suffix `x` for number literal
|
||||
}
|
||||
|
|
|
@ -18,10 +18,13 @@ struct Dst<X: ?Sized> {
|
|||
struct TwoStrs(str, str)
|
||||
where
|
||||
str: Sized;
|
||||
//~^ ERROR: trait bound str: std::marker::Sized does not depend on any type or lifetim
|
||||
//~| NOTE: `-D trivial-bounds` implied by `-D warnings`
|
||||
|
||||
fn unsized_local()
|
||||
where
|
||||
for<'a> Dst<dyn A + 'a>: Sized,
|
||||
//~^ ERROR: trait bound for<'a> Dst<(dyn A + 'a)>: std::marker::Sized does not depend
|
||||
{
|
||||
let x: Dst<dyn A> = *(Box::new(Dst { x: 1 }) as Box<Dst<dyn A>>);
|
||||
}
|
||||
|
@ -29,6 +32,7 @@ where
|
|||
fn return_str() -> str
|
||||
where
|
||||
str: Sized,
|
||||
//~^ ERROR: trait bound str: std::marker::Sized does not depend on any type or lifetim
|
||||
{
|
||||
*"Sized".to_string().into_boxed_str()
|
||||
}
|
||||
|
@ -36,6 +40,7 @@ where
|
|||
fn use_op(s: String) -> String
|
||||
where
|
||||
String: ::std::ops::Neg<Output = String>,
|
||||
//~^ ERROR: trait bound std::string::String: std::ops::Neg does not depend on any type
|
||||
{
|
||||
-s
|
||||
}
|
||||
|
@ -43,6 +48,7 @@ where
|
|||
fn use_for()
|
||||
where
|
||||
i32: Iterator,
|
||||
//~^ ERROR: trait bound i32: std::iter::Iterator does not depend on any type or lifeti
|
||||
{
|
||||
for _ in 2i32 {}
|
||||
}
|
||||
|
|
|
@ -7,25 +7,25 @@ LL | str: Sized;
|
|||
= note: `-D trivial-bounds` implied by `-D warnings`
|
||||
|
||||
error: trait bound for<'a> Dst<(dyn A + 'a)>: std::marker::Sized does not depend on any type or lifetime parameters
|
||||
--> $DIR/ice-3969.rs:24:30
|
||||
--> $DIR/ice-3969.rs:26:30
|
||||
|
|
||||
LL | for<'a> Dst<dyn A + 'a>: Sized,
|
||||
| ^^^^^
|
||||
|
||||
error: trait bound str: std::marker::Sized does not depend on any type or lifetime parameters
|
||||
--> $DIR/ice-3969.rs:31:10
|
||||
--> $DIR/ice-3969.rs:34:10
|
||||
|
|
||||
LL | str: Sized,
|
||||
| ^^^^^
|
||||
|
||||
error: trait bound std::string::String: std::ops::Neg does not depend on any type or lifetime parameters
|
||||
--> $DIR/ice-3969.rs:38:13
|
||||
--> $DIR/ice-3969.rs:42:13
|
||||
|
|
||||
LL | String: ::std::ops::Neg<Output = String>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: trait bound i32: std::iter::Iterator does not depend on any type or lifetime parameters
|
||||
--> $DIR/ice-3969.rs:45:10
|
||||
--> $DIR/ice-3969.rs:50:10
|
||||
|
|
||||
LL | i32: Iterator,
|
||||
| ^^^^^^^^
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#[rustfmt::skip]
|
||||
pub struct Foo {
|
||||
/// 位
|
||||
//~^ ERROR: using tabs in doc comments is not recommended
|
||||
//~| NOTE: `-D clippy::tabs-in-doc-comments` implied by `-D warnings`
|
||||
/// ^ Do not remove this tab character.
|
||||
/// It was required to trigger the ICE.
|
||||
pub bar: u8,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#[rustfmt::skip]
|
||||
pub struct Foo {
|
||||
/// 位
|
||||
//~^ ERROR: using tabs in doc comments is not recommended
|
||||
//~| NOTE: `-D clippy::tabs-in-doc-comments` implied by `-D warnings`
|
||||
/// ^ Do not remove this tab character.
|
||||
/// It was required to trigger the ICE.
|
||||
pub bar: u8,
|
||||
|
|
|
@ -2,4 +2,6 @@
|
|||
|
||||
fn main() {
|
||||
let _ = vec![1, 2, 3].into_iter().next().is_none();
|
||||
//~^ ERROR: avoid using `collect()` when not needed
|
||||
//~| NOTE: `-D clippy::needless-collect` implied by `-D warnings`
|
||||
}
|
||||
|
|
|
@ -2,4 +2,6 @@
|
|||
|
||||
fn main() {
|
||||
let _ = vec![1, 2, 3].into_iter().collect::<Vec<_>>().is_empty();
|
||||
//~^ ERROR: avoid using `collect()` when not needed
|
||||
//~| NOTE: `-D clippy::needless-collect` implied by `-D warnings`
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ fn main() {
|
|||
// This used to cause an ICE (https://github.com/rust-lang/rust/issues/78071)
|
||||
match FOO_REF_REF {
|
||||
FOO_REF_REF => {},
|
||||
//~^ ERROR: to use a constant of type `Foo` in a pattern, `Foo` must be annotated
|
||||
//~| NOTE: for more information, see issue #62411 <https://github.com/rust-lang/ru
|
||||
Foo(_) => {},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,4 +8,6 @@ struct A<T> {
|
|||
|
||||
fn main() {
|
||||
if Ok::<_, ()>(A::<String>::default()).is_ok() {}
|
||||
//~^ ERROR: redundant pattern matching, consider using `is_ok()`
|
||||
//~| NOTE: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue