Skip to content

Commit d0f6d54

Browse files
committed
Added additional tests
1 parent af46003 commit d0f6d54

File tree

2 files changed

+115
-6
lines changed

2 files changed

+115
-6
lines changed

tests/ui/implicit_saturating_sub.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ fn main() {
102102
i_8 -= 1;
103103
}
104104

105+
// Lint
106+
if i_8 != i8::MIN {
107+
i_8 -= 1;
108+
}
109+
110+
// Lint
111+
if i_8 != i8::min_value() {
112+
i_8 -= 1;
113+
}
114+
105115
let endi_16: i16 = 45;
106116
let starti_16: i16 = 44;
107117

@@ -117,6 +127,16 @@ fn main() {
117127
i_16 -= 1;
118128
}
119129

130+
// Lint
131+
if i_16 != i16::MIN {
132+
i_16 -= 1;
133+
}
134+
135+
// Lint
136+
if i_16 != i16::min_value() {
137+
i_16 -= 1;
138+
}
139+
120140
let endi_32: i32 = 45;
121141
let starti_32: i32 = 44;
122142

@@ -132,6 +152,16 @@ fn main() {
132152
i_32 -= 1;
133153
}
134154

155+
// Lint
156+
if i_32 != i32::MIN {
157+
i_32 -= 1;
158+
}
159+
160+
// Lint
161+
if i_32 != i32::min_value() {
162+
i_32 -= 1;
163+
}
164+
135165
let endi_64: i64 = 45;
136166
let starti_64: i64 = 44;
137167

@@ -147,8 +177,23 @@ fn main() {
147177
i_64 -= 1;
148178
}
149179

180+
// Lint
181+
if i_64 != i64::MIN {
182+
i_64 -= 1;
183+
}
184+
185+
// Lint
186+
if i_64 != i64::min_value() {
187+
i_64 -= 1;
188+
}
189+
150190
// No Lint
151191
if i_64 > 0 {
152192
i_64 -= 1;
153193
}
194+
195+
// No Lint
196+
if i_64 != 0 {
197+
i_64 -= 1;
198+
}
154199
}

tests/ui/implicit_saturating_sub.stderr

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,53 +64,117 @@ LL | | i_8 -= 1;
6464
LL | | }
6565
| |_____^ help: try: `i_8 = i_8.saturating_sub(1);`
6666

67+
error: Implicitly performing saturating subtraction
68+
--> $DIR/implicit_saturating_sub.rs:106:5
69+
|
70+
LL | / if i_8 != i8::MIN {
71+
LL | | i_8 -= 1;
72+
LL | | }
73+
| |_____^ help: try: `i_8 = i_8.saturating_sub(1);`
74+
6775
error: Implicitly performing saturating subtraction
6876
--> $DIR/implicit_saturating_sub.rs:111:5
6977
|
78+
LL | / if i_8 != i8::min_value() {
79+
LL | | i_8 -= 1;
80+
LL | | }
81+
| |_____^ help: try: `i_8 = i_8.saturating_sub(1);`
82+
83+
error: Implicitly performing saturating subtraction
84+
--> $DIR/implicit_saturating_sub.rs:121:5
85+
|
7086
LL | / if i_16 > i16::MIN {
7187
LL | | i_16 -= 1;
7288
LL | | }
7389
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
7490

7591
error: Implicitly performing saturating subtraction
76-
--> $DIR/implicit_saturating_sub.rs:116:5
92+
--> $DIR/implicit_saturating_sub.rs:126:5
7793
|
7894
LL | / if i_16 > i16::min_value() {
7995
LL | | i_16 -= 1;
8096
LL | | }
8197
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
8298

8399
error: Implicitly performing saturating subtraction
84-
--> $DIR/implicit_saturating_sub.rs:126:5
100+
--> $DIR/implicit_saturating_sub.rs:131:5
101+
|
102+
LL | / if i_16 != i16::MIN {
103+
LL | | i_16 -= 1;
104+
LL | | }
105+
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
106+
107+
error: Implicitly performing saturating subtraction
108+
--> $DIR/implicit_saturating_sub.rs:136:5
109+
|
110+
LL | / if i_16 != i16::min_value() {
111+
LL | | i_16 -= 1;
112+
LL | | }
113+
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
114+
115+
error: Implicitly performing saturating subtraction
116+
--> $DIR/implicit_saturating_sub.rs:146:5
85117
|
86118
LL | / if i_32 > i32::MIN {
87119
LL | | i_32 -= 1;
88120
LL | | }
89121
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
90122

91123
error: Implicitly performing saturating subtraction
92-
--> $DIR/implicit_saturating_sub.rs:131:5
124+
--> $DIR/implicit_saturating_sub.rs:151:5
93125
|
94126
LL | / if i_32 > i32::min_value() {
95127
LL | | i_32 -= 1;
96128
LL | | }
97129
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
98130

99131
error: Implicitly performing saturating subtraction
100-
--> $DIR/implicit_saturating_sub.rs:141:5
132+
--> $DIR/implicit_saturating_sub.rs:156:5
133+
|
134+
LL | / if i_32 != i32::MIN {
135+
LL | | i_32 -= 1;
136+
LL | | }
137+
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
138+
139+
error: Implicitly performing saturating subtraction
140+
--> $DIR/implicit_saturating_sub.rs:161:5
141+
|
142+
LL | / if i_32 != i32::min_value() {
143+
LL | | i_32 -= 1;
144+
LL | | }
145+
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
146+
147+
error: Implicitly performing saturating subtraction
148+
--> $DIR/implicit_saturating_sub.rs:171:5
101149
|
102150
LL | / if i_64 > i64::MIN {
103151
LL | | i_64 -= 1;
104152
LL | | }
105153
| |_____^ help: try: `i_64 = i_64.saturating_sub(1);`
106154

107155
error: Implicitly performing saturating subtraction
108-
--> $DIR/implicit_saturating_sub.rs:146:5
156+
--> $DIR/implicit_saturating_sub.rs:176:5
109157
|
110158
LL | / if i_64 > i64::min_value() {
111159
LL | | i_64 -= 1;
112160
LL | | }
113161
| |_____^ help: try: `i_64 = i_64.saturating_sub(1);`
114162

115-
error: aborting due to 14 previous errors
163+
error: Implicitly performing saturating subtraction
164+
--> $DIR/implicit_saturating_sub.rs:181:5
165+
|
166+
LL | / if i_64 != i64::MIN {
167+
LL | | i_64 -= 1;
168+
LL | | }
169+
| |_____^ help: try: `i_64 = i_64.saturating_sub(1);`
170+
171+
error: Implicitly performing saturating subtraction
172+
--> $DIR/implicit_saturating_sub.rs:186:5
173+
|
174+
LL | / if i_64 != i64::min_value() {
175+
LL | | i_64 -= 1;
176+
LL | | }
177+
| |_____^ help: try: `i_64 = i_64.saturating_sub(1);`
178+
179+
error: aborting due to 22 previous errors
116180

0 commit comments

Comments
 (0)