diff --git a/src/needless_bool.rs b/src/needless_bool.rs index fcbc287e30f..d97e819077a 100644 --- a/src/needless_bool.rs +++ b/src/needless_bool.rs @@ -37,7 +37,7 @@ fn check_expr(&mut self, cx: &Context, e: &Expr) { "you can reduce your if statement to its predicate"); }, (Option::Some(false), Option::Some(true)) => { span_lint(cx, NEEDLESS_BOOL, e.span, - "you can reduce your if statement to `!` + your predicate"); }, + "you can reduce your if statement to `!` + its predicate"); }, (Option::Some(false), Option::Some(false)) => { span_lint(cx, NEEDLESS_BOOL, e.span, "your if-then-else expression will always return false"); }, diff --git a/tests/compile-fail/approx_const.rs b/tests/compile-fail/approx_const.rs index 3eb170b295b..799795becbd 100755 --- a/tests/compile-fail/approx_const.rs +++ b/tests/compile-fail/approx_const.rs @@ -4,53 +4,53 @@ #[deny(approx_constant)] #[allow(unused)] fn main() { - let my_e = 2.7182; //~ERROR - let almost_e = 2.718; //~ERROR + let my_e = 2.7182; //~ERROR approximate value of `f{32, 64}::E` found + let almost_e = 2.718; //~ERROR approximate value of `f{32, 64}::E` found let no_e = 2.71; - let my_1_frac_pi = 0.3183; //~ERROR + let my_1_frac_pi = 0.3183; //~ERROR approximate value of `f{32, 64}::FRAC_1_PI` found let no_1_frac_pi = 0.31; - let my_frac_1_sqrt_2 = 0.70710678; //~ERROR - let almost_frac_1_sqrt_2 = 0.70711; //~ERROR + let my_frac_1_sqrt_2 = 0.70710678; //~ERROR approximate value of `f{32, 64}::FRAC_1_SQRT_2` found + let almost_frac_1_sqrt_2 = 0.70711; //~ERROR approximate value of `f{32, 64}::FRAC_1_SQRT_2` found let my_frac_1_sqrt_2 = 0.707; - let my_frac_2_pi = 0.63661977; //~ERROR + let my_frac_2_pi = 0.63661977; //~ERROR approximate value of `f{32, 64}::FRAC_2_PI` found let no_frac_2_pi = 0.636; - let my_frac_2_sq_pi = 1.128379; //~ERROR + let my_frac_2_sq_pi = 1.128379; //~ERROR approximate value of `f{32, 64}::FRAC_2_SQRT_PI` found let no_frac_2_sq_pi = 1.128; - let my_frac_2_pi = 1.57079632679; //~ERROR - let no_frac_2_pi = 1.5705; + let my_frac_pi_2 = 1.57079632679; //~ERROR approximate value of `f{32, 64}::FRAC_PI_2` found + let no_frac_pi_2 = 1.5705; - let my_frac_3_pi = 1.04719755119; //~ERROR - let no_frac_3_pi = 1.047; + let my_frac_pi_3 = 1.04719755119; //~ERROR approximate value of `f{32, 64}::FRAC_PI_3` found + let no_frac_pi_3 = 1.047; - let my_frac_4_pi = 0.785398163397; //~ERROR - let no_frac_4_pi = 0.785; + let my_frac_pi_4 = 0.785398163397; //~ERROR approximate value of `f{32, 64}::FRAC_PI_4` found + let no_frac_pi_4 = 0.785; - let my_frac_6_pi = 0.523598775598; //~ERROR - let no_frac_6_pi = 0.523; + let my_frac_pi_6 = 0.523598775598; //~ERROR approximate value of `f{32, 64}::FRAC_PI_6` found + let no_frac_pi_6 = 0.523; - let my_frac_8_pi = 0.3926990816987; //~ERROR - let no_frac_8_pi = 0.392; + let my_frac_pi_8 = 0.3926990816987; //~ERROR approximate value of `f{32, 64}::FRAC_PI_8` found + let no_frac_pi_8 = 0.392; - let my_ln_10 = 2.302585092994046; //~ERROR + let my_ln_10 = 2.302585092994046; //~ERROR approximate value of `f{32, 64}::LN_10` found let no_ln_10 = 2.303; - let my_ln_2 = 0.6931471805599453; //~ERROR + let my_ln_2 = 0.6931471805599453; //~ERROR approximate value of `f{32, 64}::LN_2` found let no_ln_2 = 0.693; - let my_log10_e = 0.43429448190325176; //~ERROR + let my_log10_e = 0.43429448190325176; //~ERROR approximate value of `f{32, 64}::LOG10_E` found let no_log10_e = 0.434; - let my_log2_e = 1.4426950408889634; //~ERROR + let my_log2_e = 1.4426950408889634; //~ERROR approximate value of `f{32, 64}::LOG2_E` found let no_log2_e = 1.442; - let my_pi = 3.1415; //~ERROR + let my_pi = 3.1415; //~ERROR approximate value of `f{32, 64}::PI` found let almost_pi = 3.141; - let my_sq2 = 1.4142; //~ERROR + let my_sq2 = 1.4142; //~ERROR approximate value of `f{32, 64}::SQRT_2` found let no_sq2 = 1.414; } diff --git a/tests/compile-fail/bit_masks.rs b/tests/compile-fail/bit_masks.rs index c2a82483005..bcbfe99e42e 100755 --- a/tests/compile-fail/bit_masks.rs +++ b/tests/compile-fail/bit_masks.rs @@ -12,30 +12,30 @@ fn main() { x & 0 == 0; //~ERROR &-masking with zero x & 1 == 1; //ok, distinguishes bit 0 x & 1 == 0; //ok, compared with zero - x & 2 == 1; //~ERROR + x & 2 == 1; //~ERROR incompatible bit mask 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 + x | 3 == 2; //~ERROR incompatible bit mask - x & 1 > 1; //~ERROR + x & 1 > 1; //~ERROR incompatible bit mask 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 + x | 2 > 1; //~ERROR incompatible bit mask x | 2 <= 2; // ok (if a bit silly), equals x <= 2 // this also now works with constants - x & THREE_BITS == 8; //~ERROR - x | EVEN_MORE_REDIRECTION < 7; //~ERROR + x & THREE_BITS == 8; //~ERROR incompatible bit mask + x | EVEN_MORE_REDIRECTION < 7; //~ERROR incompatible bit mask - 0 & x == 0; //~ERROR + 0 & x == 0; //~ERROR &-masking with zero 1 | x > 1; // and should now also match uncommon usage - 1 < 2 | x; //~ERROR - 2 == 3 | x; //~ERROR - 1 == x & 2; //~ERROR + 1 < 2 | x; //~ERROR incompatible bit mask + 2 == 3 | x; //~ERROR incompatible bit mask + 1 == x & 2; //~ERROR incompatible bit mask x | 1 > 2; // no error, because we allowed ineffective bit masks ineffective(); @@ -46,8 +46,8 @@ fn main() { fn ineffective() { let x = 5; - x | 1 > 2; //~ERROR - x | 1 < 3; //~ERROR - x | 1 <= 3; //~ERROR - x | 1 >= 2; //~ERROR + x | 1 > 2; //~ERROR ineffective bit mask + x | 1 < 3; //~ERROR ineffective bit mask + x | 1 <= 3; //~ERROR ineffective bit mask + x | 1 >= 2; //~ERROR ineffective bit mask } diff --git a/tests/compile-fail/cmp_nan.rs b/tests/compile-fail/cmp_nan.rs index b6549c2c1fb..b2369e164ff 100755 --- a/tests/compile-fail/cmp_nan.rs +++ b/tests/compile-fail/cmp_nan.rs @@ -5,18 +5,18 @@ #[allow(float_cmp)] fn main() { let x = 5f32; - x == std::f32::NAN; //~ERROR - x != std::f32::NAN; //~ERROR - x < std::f32::NAN; //~ERROR - x > std::f32::NAN; //~ERROR - x <= std::f32::NAN; //~ERROR - x >= std::f32::NAN; //~ERROR + x == std::f32::NAN; //~ERROR doomed comparison with NAN + x != std::f32::NAN; //~ERROR doomed comparison with NAN + x < std::f32::NAN; //~ERROR doomed comparison with NAN + x > std::f32::NAN; //~ERROR doomed comparison with NAN + x <= std::f32::NAN; //~ERROR doomed comparison with NAN + x >= std::f32::NAN; //~ERROR doomed comparison with NAN let y = 0f64; - y == std::f64::NAN; //~ERROR - y != std::f64::NAN; //~ERROR - y < std::f64::NAN; //~ERROR - y > std::f64::NAN; //~ERROR - y <= std::f64::NAN; //~ERROR - y >= std::f64::NAN; //~ERROR + y == std::f64::NAN; //~ERROR doomed comparison with NAN + y != std::f64::NAN; //~ERROR doomed comparison with NAN + y < std::f64::NAN; //~ERROR doomed comparison with NAN + y > std::f64::NAN; //~ERROR doomed comparison with NAN + y <= std::f64::NAN; //~ERROR doomed comparison with NAN + y >= std::f64::NAN; //~ERROR doomed comparison with NAN } diff --git a/tests/compile-fail/eq_op.rs b/tests/compile-fail/eq_op.rs index 45fce0c0bb3..298132013a9 100755 --- a/tests/compile-fail/eq_op.rs +++ b/tests/compile-fail/eq_op.rs @@ -9,29 +9,29 @@ fn id(x: X) -> X { #[allow(identity_op)] fn main() { // simple values and comparisons - 1 == 1; //~ERROR - "no" == "no"; //~ERROR + 1 == 1; //~ERROR equal expressions + "no" == "no"; //~ERROR equal expressions // even though I agree that no means no ;-) - false != false; //~ERROR - 1.5 < 1.5; //~ERROR - 1u64 >= 1u64; //~ERROR + false != false; //~ERROR equal expressions + 1.5 < 1.5; //~ERROR equal expressions + 1u64 >= 1u64; //~ERROR equal expressions // casts, methods, parenthesis - (1 as u64) & (1 as u64); //~ERROR - 1 ^ ((((((1)))))); //~ERROR - id((1)) | id(1); //~ERROR + (1 as u64) & (1 as u64); //~ERROR equal expressions + 1 ^ ((((((1)))))); //~ERROR equal expressions + id((1)) | id(1); //~ERROR equal expressions // unary and binary operators - (-(2) < -(2)); //~ERROR + (-(2) < -(2)); //~ERROR equal expressions ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); - //~^ ERROR - //~^^ ERROR - //~^^^ ERROR - (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; //~ERROR + //~^ ERROR equal expressions + //~^^ ERROR equal expressions + //~^^^ ERROR equal expressions + (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; //~ERROR equal expressions // various other things - ([1] != [1]); //~ERROR - ((1, 2) != (1, 2)); //~ERROR - [1].len() == [1].len(); //~ERROR + ([1] != [1]); //~ERROR equal expressions + ((1, 2) != (1, 2)); //~ERROR equal expressions + [1].len() == [1].len(); //~ERROR equal expressions vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros } diff --git a/tests/compile-fail/float_cmp.rs b/tests/compile-fail/float_cmp.rs index 2305e42161a..419e500d0fc 100755 --- a/tests/compile-fail/float_cmp.rs +++ b/tests/compile-fail/float_cmp.rs @@ -13,20 +13,20 @@ fn twice(x : T) -> T where T : Add, T : Copy { #[deny(float_cmp)] #[allow(unused)] fn main() { - ZERO == 0f32; //~ERROR - ZERO == 0.0; //~ERROR - ZERO + ZERO != 1.0; //~ERROR + ZERO == 0f32; //~ERROR ==-comparison of f32 or f64 + ZERO == 0.0; //~ERROR ==-comparison of f32 or f64 + ZERO + ZERO != 1.0; //~ERROR !=-comparison of f32 or f64 ONE != 0.0; //~ERROR - twice(ONE) != ONE; //~ERROR - ONE as f64 != 0.0; //~ERROR + twice(ONE) != ONE; //~ERROR !=-comparison of f32 or f64 + ONE as f64 != 0.0; //~ERROR !=-comparison of f32 or f64 let x : f64 = 1.0; - x == 1.0; //~ERROR - x != 0f64; //~ERROR + x == 1.0; //~ERROR ==-comparison of f32 or f64 + x != 0f64; //~ERROR !=-comparison of f32 or f64 - twice(x) != twice(ONE as f64); //~ERROR + twice(x) != twice(ONE as f64); //~ERROR !=-comparison of f32 or f64 x < 0.0; x > 0.0; diff --git a/tests/compile-fail/identity_op.rs b/tests/compile-fail/identity_op.rs index cde4a615b25..987bada2ece 100755 --- a/tests/compile-fail/identity_op.rs +++ b/tests/compile-fail/identity_op.rs @@ -9,16 +9,16 @@ fn main() { let x = 0; - x + 0; //~ERROR - 0 + x; //~ERROR - x - ZERO; //~ERROR - x | (0); //~ERROR - ((ZERO)) | x; //~ERROR + x + 0; //~ERROR the operation is ineffective + 0 + x; //~ERROR the operation is ineffective + x - ZERO; //~ERROR the operation is ineffective + x | (0); //~ERROR the operation is ineffective + ((ZERO)) | x; //~ERROR the operation is ineffective - x * 1; //~ERROR - 1 * x; //~ERROR - x / ONE; //~ERROR + x * 1; //~ERROR the operation is ineffective + 1 * x; //~ERROR the operation is ineffective + x / ONE; //~ERROR the operation is ineffective - x & NEG_ONE; //~ERROR - -1 & x; //~ERROR + x & NEG_ONE; //~ERROR the operation is ineffective + -1 & x; //~ERROR the operation is ineffective } diff --git a/tests/compile-fail/let_return.rs b/tests/compile-fail/let_return.rs index 8ea4653ef0f..082378d21e2 100755 --- a/tests/compile-fail/let_return.rs +++ b/tests/compile-fail/let_return.rs @@ -6,7 +6,7 @@ fn test() -> i32 { let _y = 0; // no warning let x = 5; //~NOTE - x //~ERROR: + x //~ERROR returning the result of a let binding } fn test_nowarn_1() -> i32 { diff --git a/tests/compile-fail/let_unit.rs b/tests/compile-fail/let_unit.rs index e8620f862a2..f06a10bfe13 100755 --- a/tests/compile-fail/let_unit.rs +++ b/tests/compile-fail/let_unit.rs @@ -8,6 +8,6 @@ fn main() { let _y = 1; // this is fine let _z = ((), 1); // this as well if true { - let _a = (); //~ERROR + let _a = (); //~ERROR this let-binding has unit value } } diff --git a/tests/compile-fail/methods.rs b/tests/compile-fail/methods.rs index facf0378392..91d3b72de84 100755 --- a/tests/compile-fail/methods.rs +++ b/tests/compile-fail/methods.rs @@ -5,11 +5,11 @@ #[deny(str_to_string, string_to_string)] fn main() { let opt = Some(0); - let _ = opt.unwrap(); //~ERROR + let _ = opt.unwrap(); //~ERROR used unwrap() on an Option let res: Result = Ok(0); - let _ = res.unwrap(); //~ERROR + let _ = res.unwrap(); //~ERROR used unwrap() on a Result - let string = "str".to_string(); //~ERROR - let _again = string.to_string(); //~ERROR + let string = "str".to_string(); //~ERROR `str.to_owned()` is faster + let _again = string.to_string(); //~ERROR `String.to_string()` is a no-op } diff --git a/tests/compile-fail/mut_mut.rs b/tests/compile-fail/mut_mut.rs index 2a3f7e3958c..8aa47769539 100755 --- a/tests/compile-fail/mut_mut.rs +++ b/tests/compile-fail/mut_mut.rs @@ -5,7 +5,7 @@ //extern crate regex; #[deny(mut_mut)] -fn fun(x : &mut &mut u32) -> bool { //~ERROR +fn fun(x : &mut &mut u32) -> bool { //~ERROR generally you want to avoid `&mut &mut **x > 0 } @@ -16,19 +16,19 @@ macro_rules! mut_ptr { #[deny(mut_mut)] #[allow(unused_mut, unused_variables)] fn main() { - let mut x = &mut &mut 1u32; //~ERROR + let mut x = &mut &mut 1u32; //~ERROR generally you want to avoid `&mut &mut { - let mut y = &mut x; //~ERROR + let mut y = &mut x; //~ERROR this expression mutably borrows a mutable reference } if fun(x) { let y : &mut &mut &mut u32 = &mut &mut &mut 2; - //~^ ERROR - //~^^ ERROR - //~^^^ ERROR - //~^^^^ ERROR + //~^ ERROR generally you want to avoid `&mut &mut + //~^^ ERROR generally you want to avoid `&mut &mut + //~^^^ ERROR generally you want to avoid `&mut &mut + //~^^^^ ERROR generally you want to avoid `&mut &mut ***y + **x; } - let mut z = mut_ptr!(&mut 3u32); //~ERROR + let mut z = mut_ptr!(&mut 3u32); //~ERROR generally you want to avoid `&mut &mut } diff --git a/tests/compile-fail/needless_bool.rs b/tests/compile-fail/needless_bool.rs index 88919f39d6d..6016f79ab03 100755 --- a/tests/compile-fail/needless_bool.rs +++ b/tests/compile-fail/needless_bool.rs @@ -4,9 +4,9 @@ #[deny(needless_bool)] fn main() { let x = true; - if x { true } else { true }; //~ERROR - if x { false } else { false }; //~ERROR - if x { true } else { false }; //~ERROR - if x { false } else { true }; //~ERROR + if x { true } else { true }; //~ERROR your if-then-else expression will always return true + if x { false } else { false }; //~ERROR your if-then-else expression will always return false + if x { true } else { false }; //~ERROR you can reduce your if statement to its predicate + if x { false } else { true }; //~ERROR you can reduce your if statement to `!` + its predicate if x { x } else { false }; // would also be questionable, but we don't catch this yet } diff --git a/tests/compile-fail/needless_return.rs b/tests/compile-fail/needless_return.rs index 34d57127996..e0012942906 100755 --- a/tests/compile-fail/needless_return.rs +++ b/tests/compile-fail/needless_return.rs @@ -8,35 +8,35 @@ fn test_end_of_fn() -> bool { // no error! return true; } - return true; //~ERROR + return true; //~ERROR unneeded return statement } fn test_no_semicolon() -> bool { - return true //~ERROR + return true //~ERROR unneeded return statement } fn test_if_block() -> bool { if true { - return true; //~ERROR + return true; //~ERROR unneeded return statement } else { - return false; //~ERROR + return false; //~ERROR unneeded return statement } } fn test_match(x: bool) -> bool { match x { true => { - return false; //~ERROR + return false; //~ERROR unneeded return statement } false => { - return true //~ERROR + return true //~ERROR unneeded return statement } } } fn test_closure() { let _ = || { - return true; //~ERROR + return true; //~ERROR unneeded return statement }; } diff --git a/tests/compile-fail/precedence.rs b/tests/compile-fail/precedence.rs index fb7d06214a2..4d57f119479 100755 --- a/tests/compile-fail/precedence.rs +++ b/tests/compile-fail/precedence.rs @@ -4,12 +4,12 @@ #[deny(precedence)] #[allow(eq_op)] fn main() { - format!("{} vs. {}", 1 << 2 + 3, (1 << 2) + 3); //~ERROR - format!("{} vs. {}", 1 + 2 << 3, 1 + (2 << 3)); //~ERROR - format!("{} vs. {}", 4 >> 1 + 1, (4 >> 1) + 1); //~ERROR - format!("{} vs. {}", 1 + 3 >> 2, 1 + (3 >> 2)); //~ERROR - format!("{} vs. {}", 1 ^ 1 - 1, (1 ^ 1) - 1); //~ERROR - format!("{} vs. {}", 3 | 2 - 1, (3 | 2) - 1); //~ERROR - format!("{} vs. {}", 3 & 5 - 2, (3 & 5) - 2); //~ERROR + format!("{} vs. {}", 1 << 2 + 3, (1 << 2) + 3); //~ERROR operator precedence can trip + format!("{} vs. {}", 1 + 2 << 3, 1 + (2 << 3)); //~ERROR operator precedence can trip + format!("{} vs. {}", 4 >> 1 + 1, (4 >> 1) + 1); //~ERROR operator precedence can trip + format!("{} vs. {}", 1 + 3 >> 2, 1 + (3 >> 2)); //~ERROR operator precedence can trip + format!("{} vs. {}", 1 ^ 1 - 1, (1 ^ 1) - 1); //~ERROR operator precedence can trip + format!("{} vs. {}", 3 | 2 - 1, (3 | 2) - 1); //~ERROR operator precedence can trip + format!("{} vs. {}", 3 & 5 - 2, (3 & 5) - 2); //~ERROR operator precedence can trip } diff --git a/tests/compile-fail/ptr_arg.rs b/tests/compile-fail/ptr_arg.rs index d56ea735a1d..d4b6d22608f 100755 --- a/tests/compile-fail/ptr_arg.rs +++ b/tests/compile-fail/ptr_arg.rs @@ -3,13 +3,13 @@ #[deny(ptr_arg)] #[allow(unused)] -fn do_vec(x: &Vec) { //~ERROR: writing `&Vec<_>` instead of `&[_]` +fn do_vec(x: &Vec) { //~ERROR writing `&Vec<_>` instead of `&[_]` //Nothing here } #[deny(ptr_arg)] #[allow(unused)] -fn do_str(x: &String) { //~ERROR +fn do_str(x: &String) { //~ERROR writing `&String` instead of `&str` //Nothing here either }