2015-09-05 12:46:34 +02:00
|
|
|
#![feature(plugin)]
|
|
|
|
|
|
|
|
#![plugin(clippy)]
|
|
|
|
#![deny(clippy)]
|
|
|
|
|
|
|
|
use std::cmp::{min, max};
|
2015-11-11 17:08:33 +01:00
|
|
|
use std::cmp::min as my_min;
|
|
|
|
use std::cmp::max as my_max;
|
2015-09-05 12:46:34 +02:00
|
|
|
|
2015-09-05 16:24:41 +02:00
|
|
|
const LARGE : usize = 3;
|
|
|
|
|
2015-09-05 12:46:34 +02:00
|
|
|
fn main() {
|
|
|
|
let x;
|
|
|
|
x = 2usize;
|
|
|
|
min(1, max(3, x)); //~ERROR this min/max combination leads to constant result
|
|
|
|
min(max(3, x), 1); //~ERROR this min/max combination leads to constant result
|
|
|
|
max(min(x, 1), 3); //~ERROR this min/max combination leads to constant result
|
|
|
|
max(3, min(x, 1)); //~ERROR this min/max combination leads to constant result
|
|
|
|
|
2015-11-11 17:08:33 +01:00
|
|
|
my_max(3, my_min(x, 1)); //~ERROR this min/max combination leads to constant result
|
|
|
|
|
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
|
|
|
|
|
2015-09-05 12:46:34 +02:00
|
|
|
let s;
|
|
|
|
s = "Hello";
|
|
|
|
|
|
|
|
min("Apple", max("Zoo", s)); //~ERROR this min/max combination leads to constant result
|
|
|
|
max(min(s, "Apple"), "Zoo"); //~ERROR this min/max combination leads to constant result
|
|
|
|
|
|
|
|
max("Apple", min(s, "Zoo")); // ok
|
|
|
|
}
|