]> git.lizzy.rs Git - rust.git/blob - tests/ui/min_max.rs
rustup and compile-fail -> ui test move
[rust.git] / tests / ui / min_max.rs
1 #![feature(plugin)]
2
3 #![plugin(clippy)]
4 #![deny(clippy)]
5
6 use std::cmp::{min, max};
7 use std::cmp::min as my_min;
8 use std::cmp::max as my_max;
9
10 const LARGE : usize = 3;
11
12 fn main() {
13     let x;
14     x = 2usize;
15     min(1, max(3, x)); //~ERROR this min/max combination leads to constant result
16     min(max(3, x), 1); //~ERROR this min/max combination leads to constant result
17     max(min(x, 1), 3); //~ERROR this min/max combination leads to constant result
18     max(3, min(x, 1)); //~ERROR this min/max combination leads to constant result
19
20     my_max(3, my_min(x, 1)); //~ERROR this min/max combination leads to constant result
21
22     min(3, max(1, x)); // ok, could be 1, 2 or 3 depending on x
23
24     min(1, max(LARGE, x)); // no error, we don't lookup consts here
25
26     let s;
27     s = "Hello";
28
29     min("Apple", max("Zoo", s)); //~ERROR this min/max combination leads to constant result
30     max(min(s, "Apple"), "Zoo"); //~ERROR this min/max combination leads to constant result
31
32     max("Apple", min(s, "Zoo")); // ok
33 }