Skip to content

Commit 892fc29

Browse files
author
FelixMaetzler
committed
added test
1 parent 1aa9745 commit 892fc29

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

tests/ui/unnecessary_min.fixed

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![allow(unused)]
22
#![warn(clippy::unnecessary_min)]
3-
43
fn main() {
54
const A: i64 = 45;
65
const B: i64 = -1;
@@ -33,6 +32,11 @@ fn main() {
3332

3433
let _ = test_i64(); // signed with MAX and function
3534
let _ = test_i64(); // signed with MAX and function
35+
36+
let mut min = u32::MAX;
37+
for _ in 0..1000 {
38+
min = min.min(random_u32()); // shouldn't lint
39+
}
3640
}
3741
fn test_usize() -> usize {
3842
42
@@ -43,3 +47,7 @@ fn test_i64() -> i64 {
4347
const fn const_fn(input: i64) -> i64 {
4448
-2 * input
4549
}
50+
fn random_u32() -> u32 {
51+
// random number generator
52+
0
53+
}

tests/ui/unnecessary_min.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![allow(unused)]
22
#![warn(clippy::unnecessary_min)]
3-
43
fn main() {
54
const A: i64 = 45;
65
const B: i64 = -1;
@@ -33,6 +32,11 @@ fn main() {
3332

3433
let _ = i64::MAX.min(test_i64()); // signed with MAX and function
3534
let _ = test_i64().min(i64::MAX); // signed with MAX and function
35+
36+
let mut min = u32::MAX;
37+
for _ in 0..1000 {
38+
min = min.min(random_u32()); // shouldn't lint
39+
}
3640
}
3741
fn test_usize() -> usize {
3842
42
@@ -43,3 +47,7 @@ fn test_i64() -> i64 {
4347
const fn const_fn(input: i64) -> i64 {
4448
-2 * input
4549
}
50+
fn random_u32() -> u32 {
51+
// random number generator
52+
0
53+
}

tests/ui/unnecessary_min.stderr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `(A * B)` is never greater than `B` and has therefore no effect
2-
--> $DIR/unnecessary_min.rs:8:13
2+
--> $DIR/unnecessary_min.rs:7:13
33
|
44
LL | let _ = (A * B).min(B); // Both are constants
55
| ^^^^^^^^^^^^^^ help: try: `(A * B)`
@@ -8,103 +8,103 @@ LL | let _ = (A * B).min(B); // Both are constants
88
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_min)]`
99

1010
error: `B` is never greater than `C` and has therefore no effect
11-
--> $DIR/unnecessary_min.rs:9:13
11+
--> $DIR/unnecessary_min.rs:8:13
1212
|
1313
LL | let _ = C.min(B); // Both are constants
1414
| ^^^^^^^^ help: try: `B`
1515

1616
error: `B` is never greater than `C` and has therefore no effect
17-
--> $DIR/unnecessary_min.rs:10:13
17+
--> $DIR/unnecessary_min.rs:9:13
1818
|
1919
LL | let _ = B.min(C); // Both are constants
2020
| ^^^^^^^^ help: try: `B`
2121

2222
error: `(-6_i32)` is never greater than `9` and has therefore no effect
23-
--> $DIR/unnecessary_min.rs:12:13
23+
--> $DIR/unnecessary_min.rs:11:13
2424
|
2525
LL | let _ = (-6_i32).min(9); // Both are Literals
2626
| ^^^^^^^^^^^^^^^ help: try: `(-6_i32)`
2727

2828
error: `6` is never greater than `9_u32` and has therefore no effect
29-
--> $DIR/unnecessary_min.rs:13:13
29+
--> $DIR/unnecessary_min.rs:12:13
3030
|
3131
LL | let _ = 9_u32.min(6); // Both are Literals
3232
| ^^^^^^^^^^^^ help: try: `6`
3333

3434
error: `6` is never greater than `7_u8` and has therefore no effect
35-
--> $DIR/unnecessary_min.rs:15:13
35+
--> $DIR/unnecessary_min.rs:14:13
3636
|
3737
LL | let _ = 6.min(7_u8); // Both are Literals
3838
| ^^^^^^^^^^^ help: try: `6`
3939

4040
error: `0` is never greater than `7_u8` and has therefore no effect
41-
--> $DIR/unnecessary_min.rs:17:13
41+
--> $DIR/unnecessary_min.rs:16:13
4242
|
4343
LL | let _ = 0.min(7_u8); // unsigned with zero
4444
| ^^^^^^^^^^^ help: try: `0`
4545

4646
error: `0_u32` is never greater than `7` and has therefore no effect
47-
--> $DIR/unnecessary_min.rs:18:13
47+
--> $DIR/unnecessary_min.rs:17:13
4848
|
4949
LL | let _ = 7.min(0_u32); // unsigned with zero
5050
| ^^^^^^^^^^^^ help: try: `0_u32`
5151

5252
error: `i32::MIN` is never greater than `42` and has therefore no effect
53-
--> $DIR/unnecessary_min.rs:20:13
53+
--> $DIR/unnecessary_min.rs:19:13
5454
|
5555
LL | let _ = i32::MIN.min(42); // singed MIN
5656
| ^^^^^^^^^^^^^^^^ help: try: `i32::MIN`
5757

5858
error: `i32::MIN` is never greater than `42` and has therefore no effect
59-
--> $DIR/unnecessary_min.rs:21:13
59+
--> $DIR/unnecessary_min.rs:20:13
6060
|
6161
LL | let _ = 42.min(i32::MIN); // singed MIN
6262
| ^^^^^^^^^^^^^^^^ help: try: `i32::MIN`
6363

6464
error: `42` is never greater than `i32::MAX` and has therefore no effect
65-
--> $DIR/unnecessary_min.rs:23:13
65+
--> $DIR/unnecessary_min.rs:22:13
6666
|
6767
LL | let _ = i32::MAX.min(42); // singed MAX
6868
| ^^^^^^^^^^^^^^^^ help: try: `42`
6969

7070
error: `42` is never greater than `i32::MAX` and has therefore no effect
71-
--> $DIR/unnecessary_min.rs:24:13
71+
--> $DIR/unnecessary_min.rs:23:13
7272
|
7373
LL | let _ = 42.min(i32::MAX); // singed MAX
7474
| ^^^^^^^^^^^^^^^^ help: try: `42`
7575

7676
error: `0` is never greater than `test_usize()` and has therefore no effect
77-
--> $DIR/unnecessary_min.rs:26:13
77+
--> $DIR/unnecessary_min.rs:25:13
7878
|
7979
LL | let _ = 0.min(test_usize()); // unsigned with zero and function
8080
| ^^^^^^^^^^^^^^^^^^^ help: try: `0`
8181

8282
error: `0` is never greater than `test_usize()` and has therefore no effect
83-
--> $DIR/unnecessary_min.rs:28:13
83+
--> $DIR/unnecessary_min.rs:27:13
8484
|
8585
LL | let _ = test_usize().min(0); // unsigned with zero and function
8686
| ^^^^^^^^^^^^^^^^^^^ help: try: `0`
8787

8888
error: `i64::MIN` is never greater than `test_i64()` and has therefore no effect
89-
--> $DIR/unnecessary_min.rs:30:13
89+
--> $DIR/unnecessary_min.rs:29:13
9090
|
9191
LL | let _ = i64::MIN.min(test_i64()); // signed with MIN and function
9292
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i64::MIN`
9393

9494
error: `i64::MIN` is never greater than `test_i64()` and has therefore no effect
95-
--> $DIR/unnecessary_min.rs:32:13
95+
--> $DIR/unnecessary_min.rs:31:13
9696
|
9797
LL | let _ = test_i64().min(i64::MIN); // signed with MIN and function
9898
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i64::MIN`
9999

100100
error: `test_i64()` is never greater than `i64::MAX` and has therefore no effect
101-
--> $DIR/unnecessary_min.rs:34:13
101+
--> $DIR/unnecessary_min.rs:33:13
102102
|
103103
LL | let _ = i64::MAX.min(test_i64()); // signed with MAX and function
104104
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `test_i64()`
105105

106106
error: `test_i64()` is never greater than `i64::MAX` and has therefore no effect
107-
--> $DIR/unnecessary_min.rs:35:13
107+
--> $DIR/unnecessary_min.rs:34:13
108108
|
109109
LL | let _ = test_i64().min(i64::MAX); // signed with MAX and function
110110
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `test_i64()`

0 commit comments

Comments
 (0)