]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/erasing_op.rs
Auto merge of #97944 - nikic:freebsd-update, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / erasing_op.rs
1 struct Length(u8);
2 struct Meter;
3
4 impl core::ops::Mul<Meter> for u8 {
5     type Output = Length;
6     fn mul(self, _: Meter) -> Length {
7         Length(self)
8     }
9 }
10
11 #[derive(Clone, Default, PartialEq, Eq, Hash)]
12 struct Vec1 {
13     x: i32,
14 }
15
16 impl core::ops::Mul<Vec1> for i32 {
17     type Output = Vec1;
18     fn mul(self, mut right: Vec1) -> Vec1 {
19         right.x *= self;
20         right
21     }
22 }
23
24 impl core::ops::Mul<i32> for Vec1 {
25     type Output = Vec1;
26     fn mul(mut self, right: i32) -> Vec1 {
27         self.x *= right;
28         self
29     }
30 }
31
32 #[allow(clippy::no_effect)]
33 #[warn(clippy::erasing_op)]
34 fn main() {
35     let x: u8 = 0;
36
37     x * 0;
38     0 & x;
39     0 / x;
40     0 * Meter; // no error: Output type is different from the non-zero argument
41     0 * Vec1 { x: 5 };
42     Vec1 { x: 5 } * 0;
43 }