2015-09-05 05:46:34 -05:00
|
|
|
|
2017-09-18 05:47:33 -05:00
|
|
|
|
|
|
|
|
2017-05-17 07:19:44 -05:00
|
|
|
#![warn(clippy)]
|
2015-09-05 05:46:34 -05:00
|
|
|
|
|
|
|
use std::cmp::{min, max};
|
2015-11-11 10:08:33 -06:00
|
|
|
use std::cmp::min as my_min;
|
|
|
|
use std::cmp::max as my_max;
|
2015-09-05 05:46:34 -05:00
|
|
|
|
2015-09-05 09:24:41 -05:00
|
|
|
const LARGE : usize = 3;
|
|
|
|
|
2015-09-05 05:46:34 -05:00
|
|
|
fn main() {
|
|
|
|
let x;
|
|
|
|
x = 2usize;
|
2017-02-08 07:58:07 -06:00
|
|
|
min(1, max(3, x));
|
|
|
|
min(max(3, x), 1);
|
|
|
|
max(min(x, 1), 3);
|
|
|
|
max(3, min(x, 1));
|
2015-09-05 05:46:34 -05:00
|
|
|
|
2017-02-08 07:58:07 -06:00
|
|
|
my_max(3, my_min(x, 1));
|
2015-11-11 10:08:33 -06:00
|
|
|
|
2015-09-05 05:46:34 -05:00
|
|
|
min(3, max(1, x)); // ok, could be 1, 2 or 3 depending on x
|
|
|
|
|
2015-09-05 09:24:41 -05:00
|
|
|
min(1, max(LARGE, x)); // no error, we don't lookup consts here
|
|
|
|
|
2015-09-05 05:46:34 -05:00
|
|
|
let s;
|
|
|
|
s = "Hello";
|
|
|
|
|
2017-02-08 07:58:07 -06:00
|
|
|
min("Apple", max("Zoo", s));
|
|
|
|
max(min(s, "Apple"), "Zoo");
|
2015-09-05 05:46:34 -05:00
|
|
|
|
|
|
|
max("Apple", min(s, "Zoo")); // ok
|
|
|
|
}
|