rust/tests/ui/assign_ops.rs

86 lines
2.8 KiB
Rust
Raw Normal View History

2016-05-11 08:32:20 -05:00
#![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
2016-06-29 14:24:20 -05:00
i += 2 + 17; //~ ERROR assign operation detected
//~^ HELP replace it with
//~| SUGGESTION i = i + 2 + 17
2016-05-11 08:32:20 -05:00
i -= 6; //~ ERROR assign operation detected
//~^ HELP replace it with
//~| SUGGESTION i = i - 6
2016-06-29 14:24:20 -05:00
i -= 2 - 1;
//~^ ERROR assign operation detected
//~| HELP replace it with
//~| SUGGESTION i = i - (2 - 1)
2016-05-11 08:32:20 -05:00
i *= 5; //~ ERROR assign operation detected
//~^ HELP replace it with
//~| SUGGESTION i = i * 5
2016-06-29 14:24:20 -05:00
i *= 1+5; //~ ERROR assign operation detected
//~^ HELP replace it with
//~| SUGGESTION i = i * (1+5)
2016-05-11 08:32:20 -05:00
i /= 32; //~ ERROR assign operation detected
//~^ HELP replace it with
//~| SUGGESTION i = i / 32
2016-06-29 14:24:20 -05:00
i /= 32 | 5; //~ ERROR assign operation detected
//~^ HELP replace it with
//~| SUGGESTION i = i / (32 | 5)
i /= 32 / 5; //~ ERROR assign operation detected
//~^ HELP replace it with
//~| SUGGESTION i = i / (32 / 5)
2016-05-11 08:32:20 -05:00
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)
2016-06-29 14:24:20 -05:00
i += 1 << 5;
//~^ ERROR assign operation detected
//~| HELP replace it with
//~| SUGGESTION i = i + (1 << 5)
2016-05-11 08:32:20 -05:00
}
#[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";
}