]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/min_max.rs
Rollup merge of #102072 - scottmcm:ptr-alignment-type, r=thomcc
[rust.git] / src / tools / clippy / tests / ui / min_max.rs
1 #![warn(clippy::all)]
2 #![allow(clippy::manual_clamp)]
3
4 use std::cmp::max as my_max;
5 use std::cmp::min as my_min;
6 use std::cmp::{max, min};
7
8 const LARGE: usize = 3;
9
10 struct NotOrd(u64);
11
12 impl NotOrd {
13     fn min(self, x: u64) -> NotOrd {
14         NotOrd(x)
15     }
16
17     fn max(self, x: u64) -> NotOrd {
18         NotOrd(x)
19     }
20 }
21
22 fn main() {
23     let 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 = "Hello";
39     min("Apple", max("Zoo", s));
40     max(min(s, "Apple"), "Zoo");
41
42     max("Apple", min(s, "Zoo")); // ok
43
44     let f = 3f32;
45     x.min(1).max(3);
46     x.max(3).min(1);
47     f.max(3f32).min(1f32);
48
49     x.max(1).min(3); // ok
50     x.min(3).max(1); // ok
51     f.min(3f32).max(1f32); // ok
52
53     max(x.min(1), 3);
54     min(x.max(1), 3); // ok
55
56     s.max("Zoo").min("Apple");
57     s.min("Apple").max("Zoo");
58
59     s.min("Zoo").max("Apple"); // ok
60
61     let not_ord = NotOrd(1);
62     not_ord.min(1).max(3); // ok
63 }