]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/assign_ops2.rs
Auto merge of #84620 - Dylan-DPC:rollup-wkv97im, r=Dylan-DPC
[rust.git] / src / tools / clippy / tests / ui / assign_ops2.rs
1 #[allow(unused_assignments)]
2 #[warn(clippy::misrefactored_assign_op, clippy::assign_op_pattern)]
3 fn main() {
4     let mut a = 5;
5     a += a + 1;
6     a += 1 + a;
7     a -= a - 1;
8     a *= a * 99;
9     a *= 42 * a;
10     a /= a / 2;
11     a %= a % 5;
12     a &= a & 1;
13     a *= a * a;
14     a = a * a * a;
15     a = a * 42 * a;
16     a = a * 2 + 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 }
43
44 fn cow_add_assign() {
45     use std::borrow::Cow;
46     let mut buf = Cow::Owned(String::from("bar"));
47     let cows = Cow::Borrowed("foo");
48
49     // this can be linted
50     buf = buf + cows.clone();
51
52     // this should not as cow<str> Add is not commutative
53     buf = cows + buf;
54     println!("{}", buf);
55 }