Skip to content

Commit 9d33968

Browse files
test: external crate consts
1 parent 4b0eb1a commit 9d33968

7 files changed

+234
-53
lines changed

tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.fixed

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
//@aux-build:../../ui/auxiliary/external_consts.rs
2+
13
#![allow(unused)]
24
#![warn(clippy::unnecessary_min_or_max)]
5+
#![allow(clippy::identity_op)]
6+
7+
extern crate external_consts;
8+
9+
const X: i32 = 1;
10+
311
fn main() {
412
// Both are Literals
513
let _ = (-6_i32);
@@ -9,6 +17,15 @@ fn main() {
917
let _ = 6;
1018
let _ = 7_u8;
1119

20+
let _ = 12;
21+
let _ = X;
22+
let _ = X;
23+
let _ = 12;
24+
let _ = 12;
25+
let _ = (X + 1);
26+
let _ = X - 1;
27+
let _ = 12;
28+
1229
let x: i32 = 42;
1330
// signed MIN
1431
let _ = i32::MIN;
@@ -43,6 +60,16 @@ fn main() {
4360

4461
let _ = std::f64::consts::E;
4562

63+
let _ = external_consts::MAGIC_NUMBER;
64+
let _ = 2;
65+
let _ = external_consts::MAGIC_NUMBER;
66+
let _ = 2;
67+
68+
let _ = external_consts::MAGIC_NUMBER;
69+
let _ = external_consts::MAGIC_NUMBER;
70+
let _ = X;
71+
let _ = X;
72+
4673
// The below cases shouldn't be lint
4774
let mut min = u32::MAX;
4875
for _ in 0..1000 {

tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
//@aux-build:../../ui/auxiliary/external_consts.rs
2+
13
#![allow(unused)]
24
#![warn(clippy::unnecessary_min_or_max)]
5+
#![allow(clippy::identity_op)]
6+
7+
extern crate external_consts;
8+
9+
const X: i32 = 1;
10+
311
fn main() {
412
// Both are Literals
513
let _ = (-6_i32).min(9);
@@ -9,6 +17,15 @@ fn main() {
917
let _ = 6.min(7_u8);
1018
let _ = 6.max(7_u8);
1119

20+
let _ = X.max(12);
21+
let _ = X.min(12);
22+
let _ = 12.min(X);
23+
let _ = 12.max(X);
24+
let _ = (X + 1).max(12);
25+
let _ = (X + 1).min(12);
26+
let _ = 12.min(X - 1);
27+
let _ = 12.max(X - 1);
28+
1229
let x: i32 = 42;
1330
// signed MIN
1431
let _ = i32::MIN.min(x);
@@ -43,6 +60,16 @@ fn main() {
4360

4461
let _ = (6.0_f64).min(std::f64::consts::E);
4562

63+
let _ = 2.min(external_consts::MAGIC_NUMBER);
64+
let _ = 2.max(external_consts::MAGIC_NUMBER);
65+
let _ = external_consts::MAGIC_NUMBER.min(2);
66+
let _ = external_consts::MAGIC_NUMBER.max(2);
67+
68+
let _ = X.min(external_consts::MAGIC_NUMBER);
69+
let _ = X.max(external_consts::MAGIC_NUMBER);
70+
let _ = external_consts::MAGIC_NUMBER.min(X);
71+
let _ = external_consts::MAGIC_NUMBER.max(X);
72+
4673
// The below cases shouldn't be lint
4774
let mut min = u32::MAX;
4875
for _ in 0..1000 {
Lines changed: 124 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `(-6_i32)` is never greater than `9` and has therefore no effect
2-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:5:13
2+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:13:13
33
|
44
LL | let _ = (-6_i32).min(9);
55
| ^^^^^^^^^^^^^^^ help: try: `(-6_i32)`
@@ -8,160 +8,256 @@ LL | let _ = (-6_i32).min(9);
88
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_min_or_max)]`
99

1010
error: `(-6_i32)` is never greater than `9` and has therefore no effect
11-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:6:13
11+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:14:13
1212
|
1313
LL | let _ = (-6_i32).max(9);
1414
| ^^^^^^^^^^^^^^^ help: try: `9`
1515

1616
error: `9_u32` is never smaller than `6` and has therefore no effect
17-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:7:13
17+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:15:13
1818
|
1919
LL | let _ = 9_u32.min(6);
2020
| ^^^^^^^^^^^^ help: try: `6`
2121

2222
error: `9_u32` is never smaller than `6` and has therefore no effect
23-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:8:13
23+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:16:13
2424
|
2525
LL | let _ = 9_u32.max(6);
2626
| ^^^^^^^^^^^^ help: try: `9_u32`
2727

2828
error: `6` is never greater than `7_u8` and has therefore no effect
29-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:9:13
29+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:17:13
3030
|
3131
LL | let _ = 6.min(7_u8);
3232
| ^^^^^^^^^^^ help: try: `6`
3333

3434
error: `6` is never greater than `7_u8` and has therefore no effect
35-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:10:13
35+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:18:13
3636
|
3737
LL | let _ = 6.max(7_u8);
3838
| ^^^^^^^^^^^ help: try: `7_u8`
3939

40+
error: `X` is never greater than `12` and has therefore no effect
41+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:20:13
42+
|
43+
LL | let _ = X.max(12);
44+
| ^^^^^^^^^ help: try: `12`
45+
46+
error: `X` is never greater than `12` and has therefore no effect
47+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:21:13
48+
|
49+
LL | let _ = X.min(12);
50+
| ^^^^^^^^^ help: try: `X`
51+
52+
error: `12` is never smaller than `X` and has therefore no effect
53+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:22:13
54+
|
55+
LL | let _ = 12.min(X);
56+
| ^^^^^^^^^ help: try: `X`
57+
58+
error: `12` is never smaller than `X` and has therefore no effect
59+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:23:13
60+
|
61+
LL | let _ = 12.max(X);
62+
| ^^^^^^^^^ help: try: `12`
63+
64+
error: `(X + 1)` is never greater than `12` and has therefore no effect
65+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:24:13
66+
|
67+
LL | let _ = (X + 1).max(12);
68+
| ^^^^^^^^^^^^^^^ help: try: `12`
69+
70+
error: `(X + 1)` is never greater than `12` and has therefore no effect
71+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:25:13
72+
|
73+
LL | let _ = (X + 1).min(12);
74+
| ^^^^^^^^^^^^^^^ help: try: `(X + 1)`
75+
76+
error: `12` is never smaller than `X - 1` and has therefore no effect
77+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:26:13
78+
|
79+
LL | let _ = 12.min(X - 1);
80+
| ^^^^^^^^^^^^^ help: try: `X - 1`
81+
82+
error: `12` is never smaller than `X - 1` and has therefore no effect
83+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:27:13
84+
|
85+
LL | let _ = 12.max(X - 1);
86+
| ^^^^^^^^^^^^^ help: try: `12`
87+
4088
error: `i32::MIN` is never greater than `x` and has therefore no effect
41-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:14:13
89+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:31:13
4290
|
4391
LL | let _ = i32::MIN.min(x);
4492
| ^^^^^^^^^^^^^^^ help: try: `i32::MIN`
4593

4694
error: `i32::MIN` is never greater than `x` and has therefore no effect
47-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:15:13
95+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:32:13
4896
|
4997
LL | let _ = i32::MIN.max(x);
5098
| ^^^^^^^^^^^^^^^ help: try: `x`
5199

52100
error: `x` is never smaller than `i32::MIN` and has therefore no effect
53-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:16:13
101+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:33:13
54102
|
55103
LL | let _ = x.min(i32::MIN);
56104
| ^^^^^^^^^^^^^^^ help: try: `i32::MIN`
57105

58106
error: `x` is never smaller than `i32::MIN` and has therefore no effect
59-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:17:13
107+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:34:13
60108
|
61109
LL | let _ = x.max(i32::MIN);
62110
| ^^^^^^^^^^^^^^^ help: try: `x`
63111

64112
error: `i32::MAX` is never smaller than `x` and has therefore no effect
65-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:20:13
113+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:37:13
66114
|
67115
LL | let _ = i32::MAX.min(x);
68116
| ^^^^^^^^^^^^^^^ help: try: `x`
69117

70118
error: `i32::MAX` is never smaller than `x` and has therefore no effect
71-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:21:13
119+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:38:13
72120
|
73121
LL | let _ = i32::MAX.max(x);
74122
| ^^^^^^^^^^^^^^^ help: try: `i32::MAX`
75123

76124
error: `x` is never greater than `i32::MAX` and has therefore no effect
77-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:22:13
125+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:39:13
78126
|
79127
LL | let _ = x.min(i32::MAX);
80128
| ^^^^^^^^^^^^^^^ help: try: `x`
81129

82130
error: `x` is never greater than `i32::MAX` and has therefore no effect
83-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:23:13
131+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:40:13
84132
|
85133
LL | let _ = x.max(i32::MAX);
86134
| ^^^^^^^^^^^^^^^ help: try: `i32::MAX`
87135

88136
error: `u32::MAX` is never smaller than `x` and has therefore no effect
89-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:27:13
137+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:44:13
90138
|
91139
LL | let _ = u32::MAX.min(x);
92140
| ^^^^^^^^^^^^^^^ help: try: `x`
93141

94142
error: `u32::MAX` is never smaller than `x` and has therefore no effect
95-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:28:13
143+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:45:13
96144
|
97145
LL | let _ = u32::MAX.max(x);
98146
| ^^^^^^^^^^^^^^^ help: try: `u32::MAX`
99147

100148
error: `x` is never greater than `u32::MAX` and has therefore no effect
101-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:29:13
149+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:46:13
102150
|
103151
LL | let _ = x.min(u32::MAX);
104152
| ^^^^^^^^^^^^^^^ help: try: `x`
105153

106154
error: `x` is never greater than `u32::MAX` and has therefore no effect
107-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:30:13
155+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:47:13
108156
|
109157
LL | let _ = x.max(u32::MAX);
110158
| ^^^^^^^^^^^^^^^ help: try: `u32::MAX`
111159

112160
error: `u32::MIN` is never greater than `x` and has therefore no effect
113-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:33:13
161+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:50:13
114162
|
115163
LL | let _ = u32::MIN.min(x);
116164
| ^^^^^^^^^^^^^^^ help: try: `u32::MIN`
117165

118166
error: `u32::MIN` is never greater than `x` and has therefore no effect
119-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:34:13
167+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:51:13
120168
|
121169
LL | let _ = u32::MIN.max(x);
122170
| ^^^^^^^^^^^^^^^ help: try: `x`
123171

124172
error: `x` is never smaller than `u32::MIN` and has therefore no effect
125-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:35:13
173+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:52:13
126174
|
127175
LL | let _ = x.min(u32::MIN);
128176
| ^^^^^^^^^^^^^^^ help: try: `u32::MIN`
129177

130178
error: `x` is never smaller than `u32::MIN` and has therefore no effect
131-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:36:13
179+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:53:13
132180
|
133181
LL | let _ = x.max(u32::MIN);
134182
| ^^^^^^^^^^^^^^^ help: try: `x`
135183

136184
error: `0` is never greater than `x` and has therefore no effect
137-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:39:13
185+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:56:13
138186
|
139187
LL | let _ = 0.min(x);
140188
| ^^^^^^^^ help: try: `0`
141189

142190
error: `0` is never greater than `x` and has therefore no effect
143-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:40:13
191+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:57:13
144192
|
145193
LL | let _ = 0.max(x);
146194
| ^^^^^^^^ help: try: `x`
147195

148196
error: `x` is never smaller than `0_u32` and has therefore no effect
149-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:41:13
197+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:58:13
150198
|
151199
LL | let _ = x.min(0_u32);
152200
| ^^^^^^^^^^^^ help: try: `0_u32`
153201

154202
error: `x` is never smaller than `0_u32` and has therefore no effect
155-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:42:13
203+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:59:13
156204
|
157205
LL | let _ = x.max(0_u32);
158206
| ^^^^^^^^^^^^ help: try: `x`
159207

160208
error: `(6.0_f64)` is never smaller than `std::f64::consts::E` and has therefore no effect
161-
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:44:13
209+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:61:13
162210
|
163211
LL | let _ = (6.0_f64).min(std::f64::consts::E);
164212
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::f64::consts::E`
165213

166-
error: aborting due to 27 previous errors
214+
error: `2` is never smaller than `external_consts::MAGIC_NUMBER` and has therefore no effect
215+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:63:13
216+
|
217+
LL | let _ = 2.min(external_consts::MAGIC_NUMBER);
218+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `external_consts::MAGIC_NUMBER`
219+
220+
error: `2` is never smaller than `external_consts::MAGIC_NUMBER` and has therefore no effect
221+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:64:13
222+
|
223+
LL | let _ = 2.max(external_consts::MAGIC_NUMBER);
224+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `2`
225+
226+
error: `external_consts::MAGIC_NUMBER` is never greater than `2` and has therefore no effect
227+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:65:13
228+
|
229+
LL | let _ = external_consts::MAGIC_NUMBER.min(2);
230+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `external_consts::MAGIC_NUMBER`
231+
232+
error: `external_consts::MAGIC_NUMBER` is never greater than `2` and has therefore no effect
233+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:66:13
234+
|
235+
LL | let _ = external_consts::MAGIC_NUMBER.max(2);
236+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `2`
237+
238+
error: `X` is never smaller than `external_consts::MAGIC_NUMBER` and has therefore no effect
239+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:68:13
240+
|
241+
LL | let _ = X.min(external_consts::MAGIC_NUMBER);
242+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `external_consts::MAGIC_NUMBER`
243+
244+
error: `X` is never smaller than `external_consts::MAGIC_NUMBER` and has therefore no effect
245+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:69:13
246+
|
247+
LL | let _ = X.max(external_consts::MAGIC_NUMBER);
248+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `external_consts::MAGIC_NUMBER`
249+
250+
error: `external_consts::MAGIC_NUMBER` is never smaller than `X` and has therefore no effect
251+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:70:13
252+
|
253+
LL | let _ = external_consts::MAGIC_NUMBER.min(X);
254+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `X`
255+
256+
error: `external_consts::MAGIC_NUMBER` is never smaller than `X` and has therefore no effect
257+
--> tests/ui-toml/unnecessary_min_or_max/unnecessary_min_or_max.rs:71:13
258+
|
259+
LL | let _ = external_consts::MAGIC_NUMBER.max(X);
260+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `X`
261+
262+
error: aborting due to 43 previous errors
167263

tests/ui/auxiliary/external_consts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub const MAGIC_NUMBER: i32 = 1;

0 commit comments

Comments
 (0)