2018-10-06 18:18:06 +02:00
|
|
|
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2018-07-28 17:34:52 +02:00
|
|
|
#![warn(clippy::all)]
|
2015-09-05 12:46:34 +02:00
|
|
|
|
2015-11-11 17:08:33 +01:00
|
|
|
use std::cmp::max as my_max;
|
2018-12-09 23:26:16 +01:00
|
|
|
use std::cmp::min as my_min;
|
|
|
|
use std::cmp::{max, min};
|
2015-09-05 12:46:34 +02:00
|
|
|
|
2018-12-09 23:26:16 +01:00
|
|
|
const LARGE: usize = 3;
|
2015-09-05 16:24:41 +02:00
|
|
|
|
2015-09-05 12:46:34 +02:00
|
|
|
fn main() {
|
|
|
|
let x;
|
|
|
|
x = 2usize;
|
2017-02-08 14:58:07 +01:00
|
|
|
min(1, max(3, x));
|
|
|
|
min(max(3, x), 1);
|
|
|
|
max(min(x, 1), 3);
|
|
|
|
max(3, min(x, 1));
|
2015-09-05 12:46:34 +02:00
|
|
|
|
2017-02-08 14:58:07 +01:00
|
|
|
my_max(3, my_min(x, 1));
|
2015-11-11 17:08:33 +01:00
|
|
|
|
2015-09-05 12:46:34 +02:00
|
|
|
min(3, max(1, x)); // ok, could be 1, 2 or 3 depending on x
|
|
|
|
|
2015-09-05 16:24:41 +02:00
|
|
|
min(1, max(LARGE, x)); // no error, we don't lookup consts here
|
|
|
|
|
2018-06-16 18:33:11 +02:00
|
|
|
let y = 2isize;
|
|
|
|
min(max(y, -1), 3);
|
|
|
|
|
2015-09-05 12:46:34 +02:00
|
|
|
let s;
|
|
|
|
s = "Hello";
|
|
|
|
|
2017-02-08 14:58:07 +01:00
|
|
|
min("Apple", max("Zoo", s));
|
|
|
|
max(min(s, "Apple"), "Zoo");
|
2015-09-05 12:46:34 +02:00
|
|
|
|
|
|
|
max("Apple", min(s, "Zoo")); // ok
|
|
|
|
}
|