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