]> git.lizzy.rs Git - rust.git/blob - tests/ui/assign_ops2.rs
Improved suggestion on misrefactored_assign_op lint. Fixes #1239
[rust.git] / tests / ui / assign_ops2.rs
1
2
3
4 #[allow(unused_assignments)]
5 #[warn(misrefactored_assign_op)]
6 fn main() {
7     let mut a = 5;
8     a += a + 1;
9     a += 1 + a;
10     a -= a - 1;
11     a *= a * 99;
12     a *= 42 * a;
13     a /= a / 2;
14     a %= a % 5;
15     a &= a & 1;
16     a *= a * a;
17     a -= 1 - a;
18     a /= 5 / a;
19     a %= 42 % a;
20     a <<= 6 << a;
21 }
22
23 // check that we don't lint on op assign impls, because that's just the way to impl them
24
25 use std::ops::{Mul, MulAssign};
26
27 #[derive(Copy, Clone, Debug, PartialEq)]
28 pub struct Wrap(i64);
29
30 impl Mul<i64> for Wrap {
31     type Output = Self;
32
33     fn mul(self, rhs: i64) -> Self {
34         Wrap(self.0 * rhs)
35     }
36 }
37
38 impl MulAssign<i64> for Wrap {
39     fn mul_assign(&mut self, rhs: i64) {
40         *self = *self * rhs
41     }
42 }