]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs
Merge commit '7f27e2e74ef957baa382dc05cf08df6368165c74' into clippyup
[rust.git] / src / tools / clippy / tests / ui-toml / arithmetic_side_effects_allowed / arithmetic_side_effects_allowed.rs
1 #![warn(clippy::arithmetic_side_effects)]
2
3 use core::ops::{Add, Neg};
4
5 macro_rules! create {
6     ($name:ident) => {
7         #[allow(clippy::arithmetic_side_effects)]
8         #[derive(Clone, Copy)]
9         struct $name;
10
11         impl Add<$name> for $name {
12             type Output = $name;
13             fn add(self, other: $name) -> Self::Output {
14                 todo!()
15             }
16         }
17
18         impl Add<i32> for $name {
19             type Output = $name;
20             fn add(self, other: i32) -> Self::Output {
21                 todo!()
22             }
23         }
24
25         impl Add<$name> for i32 {
26             type Output = $name;
27             fn add(self, other: $name) -> Self::Output {
28                 todo!()
29             }
30         }
31
32         impl Add<i64> for $name {
33             type Output = $name;
34             fn add(self, other: i64) -> Self::Output {
35                 todo!()
36             }
37         }
38
39         impl Add<$name> for i64 {
40             type Output = $name;
41             fn add(self, other: $name) -> Self::Output {
42                 todo!()
43             }
44         }
45
46         impl Neg for $name {
47             type Output = $name;
48             fn neg(self) -> Self::Output {
49                 todo!()
50             }
51         }
52     };
53 }
54
55 create!(Foo);
56 create!(Bar);
57 create!(Baz);
58 create!(OutOfNames);
59
60 fn lhs_and_rhs_are_equal() {
61     // is explicitly on the list
62     let _ = OutOfNames + OutOfNames;
63     // is explicitly on the list
64     let _ = Foo + Foo;
65     // is implicitly on the list
66     let _ = Bar + Bar;
67     // not on the list
68     let _ = Baz + Baz;
69 }
70
71 fn lhs_is_different() {
72     // is explicitly on the list
73     let _ = 1i32 + OutOfNames;
74     // is explicitly on the list
75     let _ = 1i32 + Foo;
76     // is implicitly on the list
77     let _ = 1i32 + Bar;
78     // not on the list
79     let _ = 1i32 + Baz;
80
81     // not on the list
82     let _ = 1i64 + Foo;
83     // is implicitly on the list
84     let _ = 1i64 + Bar;
85     // not on the list
86     let _ = 1i64 + Baz;
87 }
88
89 fn rhs_is_different() {
90     // is explicitly on the list
91     let _ = OutOfNames + 1i32;
92     // is explicitly on the list
93     let _ = Foo + 1i32;
94     // is implicitly on the list
95     let _ = Bar + 1i32;
96     // not on the list
97     let _ = Baz + 1i32;
98
99     // not on the list
100     let _ = Foo + 1i64;
101     // is implicitly on the list
102     let _ = Bar + 1i64;
103     // not on the list
104     let _ = Baz + 1i64;
105 }
106
107 fn unary() {
108     // is explicitly on the list
109     let _ = -OutOfNames;
110     // is explicitly on the list
111     let _ = -Foo;
112     // not on the list
113     let _ = -Bar;
114     // not on the list
115     let _ = -Baz;
116 }
117
118 fn main() {}