suggest a op= b
over a = a op b
This commit is contained in:
parent
855b292cda
commit
c6b4b19a43
7 changed files with 234 additions and 3 deletions
65
tests/compile-fail/assign_ops.rs
Normal file
65
tests/compile-fail/assign_ops.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
#![feature(plugin)]
|
||||
#![plugin(clippy)]
|
||||
|
||||
#[deny(assign_ops)]
|
||||
#[allow(unused_assignments)]
|
||||
fn main() {
|
||||
let mut i = 1i32;
|
||||
i += 2; //~ ERROR assign operation detected
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION i = i + 2
|
||||
i -= 6; //~ ERROR assign operation detected
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION i = i - 6
|
||||
i *= 5; //~ ERROR assign operation detected
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION i = i * 5
|
||||
i /= 32; //~ ERROR assign operation detected
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION i = i / 32
|
||||
i %= 42; //~ ERROR assign operation detected
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION i = i % 42
|
||||
i >>= i; //~ ERROR assign operation detected
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION i = i >> i
|
||||
i <<= 9 + 6 - 7; //~ ERROR assign operation detected
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION i = i << (9 + 6 - 7)
|
||||
}
|
||||
|
||||
#[allow(dead_code, unused_assignments)]
|
||||
#[deny(assign_op_pattern)]
|
||||
fn bla() {
|
||||
let mut a = 5;
|
||||
a = a + 1; //~ ERROR manual implementation of an assign operation
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION a += 1
|
||||
a = 1 + a; //~ ERROR manual implementation of an assign operation
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION a += 1
|
||||
a = a - 1; //~ ERROR manual implementation of an assign operation
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION a -= 1
|
||||
a = a * 99; //~ ERROR manual implementation of an assign operation
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION a *= 99
|
||||
a = 42 * a; //~ ERROR manual implementation of an assign operation
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION a *= 42
|
||||
a = a / 2; //~ ERROR manual implementation of an assign operation
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION a /= 2
|
||||
a = a % 5; //~ ERROR manual implementation of an assign operation
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION a %= 5
|
||||
a = a & 1; //~ ERROR manual implementation of an assign operation
|
||||
//~^ HELP replace it with
|
||||
//~| SUGGESTION a &= 1
|
||||
a = 1 - a;
|
||||
a = 5 / a;
|
||||
a = 42 % a;
|
||||
a = 6 << a;
|
||||
let mut s = String::new();
|
||||
s = s + "bla";
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue