1 #![warn(clippy::suspicious_arithmetic_impl)]
3 Add, AddAssign, BitAnd, BitOr, BitOrAssign, BitXor, Div, DivAssign, Mul, MulAssign, Rem, Shl, Shr, Sub,
12 fn add(self, other: Self) -> Self {
17 impl AddAssign for Foo {
18 fn add_assign(&mut self, other: Foo) {
19 *self = *self - other;
23 impl BitOrAssign for Foo {
24 fn bitor_assign(&mut self, other: Foo) {
26 self.0 |= 1 << idx; // OK: BinOpKind::Shl part of AssignOp as child node
30 impl MulAssign for Foo {
31 fn mul_assign(&mut self, other: Foo) {
36 impl DivAssign for Foo {
37 fn div_assign(&mut self, other: Foo) {
38 self.0 /= other.0; // OK: BinOpKind::Div == DivAssign
45 fn mul(self, other: Foo) -> Foo {
46 Foo(self.0 * other.0 % 42) // OK: BinOpKind::Rem part of BiExpr as parent node
53 fn sub(self, other: Self) -> Self {
54 Foo(self.0 * other.0 - 42) // OK: BinOpKind::Mul part of BiExpr as child node
61 fn div(self, other: Self) -> Self {
62 Foo(do_nothing(self.0 + other.0) / 42) // OK: BinOpKind::Add part of BiExpr as child node
69 fn rem(self, other: Self) -> Self {
77 fn bitand(self, other: Self) -> Self {
85 fn bitor(self, other: Self) -> Self {
93 fn bitxor(self, other: Self) -> Self {
101 fn shl(self, other: Self) -> Self {
102 Foo(self.0 >> other.0)
109 fn shr(self, other: Self) -> Self {
110 Foo(self.0 << other.0)
119 fn add(self, other: Self) -> Self {
120 Bar(self.0 & !other.0) // OK: Not part of BiExpr as child node
127 fn sub(self, other: Self) -> Self {
128 if self.0 <= other.0 {
129 Bar(-(self.0 & other.0)) // OK: Neg part of BiExpr as parent node
138 fn do_nothing(x: u32) -> u32 {
142 struct MultipleBinops(u32);
144 impl Add for MultipleBinops {
145 type Output = MultipleBinops;
147 // OK: multiple Binops in `add` impl
148 fn add(self, other: Self) -> Self::Output {
149 let mut result = self.0 + other.0;
150 if result >= u32::max_value() {
151 result -= u32::max_value();
153 MultipleBinops(result)
157 impl Mul for MultipleBinops {
158 type Output = MultipleBinops;
160 // OK: multiple Binops in `mul` impl
161 fn mul(self, other: Self) -> Self::Output {
162 let mut result: u32 = 0;
163 let size = std::cmp::max(self.0, other.0) as usize;
164 let mut v = vec![0; size + 1];
165 for i in 0..size + 1 {
168 MultipleBinops(result)