tests: use fragment of lint text for error checking
(Did not touch strings.rs, which is fixed by @llogiq's PR)
This commit is contained in:
parent
dbd396db91
commit
7aee04878f
@ -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"); },
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -9,29 +9,29 @@ fn id<X>(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
|
||||
}
|
||||
|
@ -13,20 +13,20 @@ fn twice<T>(x : T) -> T where T : Add<T, Output = T>, 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;
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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<i32, ()> = 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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
|
@ -3,13 +3,13 @@
|
||||
|
||||
#[deny(ptr_arg)]
|
||||
#[allow(unused)]
|
||||
fn do_vec(x: &Vec<i64>) { //~ERROR: writing `&Vec<_>` instead of `&[_]`
|
||||
fn do_vec(x: &Vec<i64>) { //~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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user