]> git.lizzy.rs Git - rust.git/commitdiff
add tests for Rem, BitAnd, BitOr, BitXor, Shl, and Shr
authorRyan1729 <Ryan1729@gmail.com>
Wed, 12 Aug 2020 15:17:40 +0000 (09:17 -0600)
committerRyan1729 <Ryan1729@gmail.com>
Wed, 12 Aug 2020 16:33:16 +0000 (10:33 -0600)
tests/ui/suspicious_arithmetic_impl.rs

index 60c2f3ec9b652159db0b19696b1139ca9a8bff4c..5c280efac1a876dbb849b7c81940b6d3db1b48ad 100644 (file)
@@ -1,5 +1,7 @@
 #![warn(clippy::suspicious_arithmetic_impl)]
-use std::ops::{Add, AddAssign, BitOrAssign, Div, DivAssign, Mul, MulAssign, Sub};
+use std::ops::{
+    Add, AddAssign, BitAnd, BitOr, BitOrAssign, BitXor, Div, DivAssign, Mul, MulAssign, Rem, Shl, Shr, Sub,
+};
 
 #[derive(Copy, Clone)]
 struct Foo(u32);
@@ -61,6 +63,54 @@ fn div(self, other: Self) -> Self {
     }
 }
 
+impl Rem for Foo {
+    type Output = Foo;
+
+    fn rem(self, other: Self) -> Self {
+        Foo(self.0 / other.0)
+    }
+}
+
+impl BitAnd for Foo {
+    type Output = Foo;
+
+    fn bitand(self, other: Self) -> Self {
+        Foo(self.0 | other.0)
+    }
+}
+
+impl BitOr for Foo {
+    type Output = Foo;
+
+    fn bitor(self, other: Self) -> Self {
+        Foo(self.0 ^ other.0)
+    }
+}
+
+impl BitXor for Foo {
+    type Output = Foo;
+
+    fn bitxor(self, other: Self) -> Self {
+        Foo(self.0 & other.0)
+    }
+}
+
+impl Shl for Foo {
+    type Output = Foo;
+
+    fn shl(self, other: Self) -> Self {
+        Foo(self.0 >> other.0)
+    }
+}
+
+impl Shr for Foo {
+    type Output = Foo;
+
+    fn shr(self, other: Self) -> Self {
+        Foo(self.0 << other.0)
+    }
+}
+
 struct Bar(i32);
 
 impl Add for Bar {