]> git.lizzy.rs Git - rust.git/blob - tests/ui/assign_ops2.rs
rustup and compile-fail -> ui test move
[rust.git] / tests / ui / assign_ops2.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3
4 #[allow(unused_assignments)]
5 #[deny(misrefactored_assign_op)]
6 fn main() {
7     let mut a = 5;
8     a += a + 1; //~ ERROR variable appears on both sides of an assignment operation
9     //~^ HELP replace it with
10     //~| SUGGESTION a += 1
11     a += 1 + a; //~ ERROR variable appears on both sides of an assignment operation
12     //~^ HELP replace it with
13     //~| SUGGESTION a += 1
14     a -= a - 1; //~ ERROR variable appears on both sides of an assignment operation
15     //~^ HELP replace it with
16     //~| SUGGESTION a -= 1
17     a *= a * 99; //~ ERROR variable appears on both sides of an assignment operation
18     //~^ HELP replace it with
19     //~| SUGGESTION a *= 99
20     a *= 42 * a; //~ ERROR variable appears on both sides of an assignment operation
21     //~^ HELP replace it with
22     //~| SUGGESTION a *= 42
23     a /= a / 2; //~ ERROR variable appears on both sides of an assignment operation
24     //~^ HELP replace it with
25     //~| SUGGESTION a /= 2
26     a %= a % 5; //~ ERROR variable appears on both sides of an assignment operation
27     //~^ HELP replace it with
28     //~| SUGGESTION a %= 5
29     a &= a & 1; //~ ERROR variable appears on both sides of an assignment operation
30     //~^ HELP replace it with
31     //~| SUGGESTION a &= 1
32     a -= 1 - a;
33     a /= 5 / a;
34     a %= 42 % a;
35     a <<= 6 << a;
36 }
37
38 // check that we don't lint on op assign impls, because that's just the way to impl them
39
40 use std::ops::{Mul, MulAssign};
41
42 #[derive(Copy, Clone, Debug, PartialEq)]
43 pub struct Wrap(i64);
44
45 impl Mul<i64> for Wrap {
46     type Output = Self;
47
48     fn mul(self, rhs: i64) -> Self {
49         Wrap(self.0 * rhs)
50     }
51 }
52
53 impl MulAssign<i64> for Wrap {
54     fn mul_assign(&mut self, rhs: i64) {
55         *self = *self * rhs
56     }
57 }