Skip to content

Commit f4eeff9

Browse files
committed
add tests for Rem, BitAnd, BitOr, BitXor, Shl, and Shr
1 parent c705817 commit f4eeff9

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

tests/ui/suspicious_arithmetic_impl.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![warn(clippy::suspicious_arithmetic_impl)]
2-
use std::ops::{Add, AddAssign, BitOrAssign, Div, DivAssign, Mul, MulAssign, Sub};
2+
use std::ops::{
3+
Add, AddAssign, BitAnd, BitOr, BitOrAssign, BitXor, Div, DivAssign, Mul, MulAssign, Rem, Shl, Shr, Sub,
4+
};
35

46
#[derive(Copy, Clone)]
57
struct Foo(u32);
@@ -61,6 +63,54 @@ impl Div for Foo {
6163
}
6264
}
6365

66+
impl Rem for Foo {
67+
type Output = Foo;
68+
69+
fn rem(self, other: Self) -> Self {
70+
Foo(self.0 / other.0)
71+
}
72+
}
73+
74+
impl BitAnd for Foo {
75+
type Output = Foo;
76+
77+
fn bitand(self, other: Self) -> Self {
78+
Foo(self.0 | other.0)
79+
}
80+
}
81+
82+
impl BitOr for Foo {
83+
type Output = Foo;
84+
85+
fn bitor(self, other: Self) -> Self {
86+
Foo(self.0 ^ other.0)
87+
}
88+
}
89+
90+
impl BitXor for Foo {
91+
type Output = Foo;
92+
93+
fn bitxor(self, other: Self) -> Self {
94+
Foo(self.0 & other.0)
95+
}
96+
}
97+
98+
impl Shl for Foo {
99+
type Output = Foo;
100+
101+
fn shl(self, other: Self) -> Self {
102+
Foo(self.0 >> other.0)
103+
}
104+
}
105+
106+
impl Shr for Foo {
107+
type Output = Foo;
108+
109+
fn shr(self, other: Self) -> Self {
110+
Foo(self.0 << other.0)
111+
}
112+
}
113+
64114
struct Bar(i32);
65115

66116
impl Add for Bar {

0 commit comments

Comments
 (0)