]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
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; | |
23 | x = 2usize; | |
24 | min(1, max(3, x)); | |
25 | min(max(3, x), 1); | |
26 | max(min(x, 1), 3); | |
27 | max(3, min(x, 1)); | |
28 | ||
29 | my_max(3, my_min(x, 1)); | |
30 | ||
31 | min(3, max(1, x)); // ok, could be 1, 2 or 3 depending on x | |
32 | ||
33 | min(1, max(LARGE, x)); // no error, we don't lookup consts here | |
34 | ||
35 | let y = 2isize; | |
36 | min(max(y, -1), 3); | |
37 | ||
38 | let s; | |
39 | s = "Hello"; | |
40 | ||
41 | min("Apple", max("Zoo", s)); | |
42 | max(min(s, "Apple"), "Zoo"); | |
43 | ||
44 | max("Apple", min(s, "Zoo")); // ok | |
45 | ||
46 | let f = 3f32; | |
47 | x.min(1).max(3); | |
48 | x.max(3).min(1); | |
49 | f.max(3f32).min(1f32); | |
50 | ||
51 | x.max(1).min(3); // ok | |
52 | x.min(3).max(1); // ok | |
53 | f.min(3f32).max(1f32); // ok | |
54 | ||
55 | max(x.min(1), 3); | |
56 | min(x.max(1), 3); // ok | |
57 | ||
58 | s.max("Zoo").min("Apple"); | |
59 | s.min("Apple").max("Zoo"); | |
60 | ||
61 | s.min("Zoo").max("Apple"); // ok | |
62 | ||
63 | let not_ord = NotOrd(1); | |
64 | not_ord.min(1).max(3); // ok | |
65 | } |