1 #![warn(clippy::suspicious_arithmetic_impl)]
2 use std::ops::{Add, AddAssign, BitOrAssign, Div, DivAssign, Mul, MulAssign, Sub};
10 fn add(self, other: Self) -> Self {
15 impl AddAssign for Foo {
16 fn add_assign(&mut self, other: Foo) {
17 *self = *self - other;
21 impl BitOrAssign for Foo {
22 fn bitor_assign(&mut self, other: Foo) {
24 self.0 |= 1 << idx; // OK: BinOpKind::Shl part of AssignOp as child node
28 impl MulAssign for Foo {
29 fn mul_assign(&mut self, other: Foo) {
34 impl DivAssign for Foo {
35 fn div_assign(&mut self, other: Foo) {
36 self.0 /= other.0; // OK: BinOpKind::Div == DivAssign
43 fn mul(self, other: Foo) -> Foo {
44 Foo(self.0 * other.0 % 42) // OK: BinOpKind::Rem part of BiExpr as parent node
51 fn sub(self, other: Self) -> Self {
52 Foo(self.0 * other.0 - 42) // OK: BinOpKind::Mul part of BiExpr as child node
59 fn div(self, other: Self) -> Self {
60 Foo(do_nothing(self.0 + other.0) / 42) // OK: BinOpKind::Add part of BiExpr as child node
69 fn add(self, other: Self) -> Self {
70 Bar(self.0 & !other.0) // OK: UnNot part of BiExpr as child node
77 fn sub(self, other: Self) -> Self {
78 if self.0 <= other.0 {
79 Bar(-(self.0 & other.0)) // OK: UnNeg part of BiExpr as parent node
88 fn do_nothing(x: u32) -> u32 {
92 struct MultipleBinops(u32);
94 impl Add for MultipleBinops {
95 type Output = MultipleBinops;
97 // OK: multiple Binops in `add` impl
98 fn add(self, other: Self) -> Self::Output {
99 let mut result = self.0 + other.0;
100 if result >= u32::max_value() {
101 result -= u32::max_value();
103 MultipleBinops(result)
107 impl Mul for MultipleBinops {
108 type Output = MultipleBinops;
110 // OK: multiple Binops in `mul` impl
111 fn mul(self, other: Self) -> Self::Output {
112 let mut result: u32 = 0;
113 let size = std::cmp::max(self.0, other.0) as usize;
114 let mut v = vec![0; size + 1];
115 for i in 0..size + 1 {
118 MultipleBinops(result)