]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/min_max.rs
Merge commit 'a5d597637dcb78dc73f93561ce474f23d4177c35' into clippyup
[rust.git] / src / tools / clippy / tests / ui / min_max.rs
1 #![warn(clippy::all)]
2
3 use std::cmp::max as my_max;
4 use std::cmp::min as my_min;
5 use std::cmp::{max, min};
6
7 const LARGE: usize = 3;
8
9 struct NotOrd(u64);
10
11 impl NotOrd {
12     fn min(self, x: u64) -> NotOrd {
13         NotOrd(x)
14     }
15
16     fn max(self, x: u64) -> NotOrd {
17         NotOrd(x)
18     }
19 }
20
21 fn main() {
22     let x = 2usize;
23     min(1, max(3, x));
24     min(max(3, x), 1);
25     max(min(x, 1), 3);
26     max(3, min(x, 1));
27
28     my_max(3, my_min(x, 1));
29
30     min(3, max(1, x)); // ok, could be 1, 2 or 3 depending on x
31
32     min(1, max(LARGE, x)); // no error, we don't lookup consts here
33
34     let y = 2isize;
35     min(max(y, -1), 3);
36
37     let s = "Hello";
38     min("Apple", max("Zoo", s));
39     max(min(s, "Apple"), "Zoo");
40
41     max("Apple", min(s, "Zoo")); // ok
42
43     let f = 3f32;
44     x.min(1).max(3);
45     x.max(3).min(1);
46     f.max(3f32).min(1f32);
47
48     x.max(1).min(3); // ok
49     x.min(3).max(1); // ok
50     f.min(3f32).max(1f32); // ok
51
52     max(x.min(1), 3);
53     min(x.max(1), 3); // ok
54
55     s.max("Zoo").min("Apple");
56     s.min("Apple").max("Zoo");
57
58     s.min("Zoo").max("Apple"); // ok
59
60     let not_ord = NotOrd(1);
61     not_ord.min(1).max(3); // ok
62 }