]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/min_max.rs
Rollup merge of #92849 - flip1995:clippyup, r=Manishearth
[rust.git] / tests / ui / min_max.rs
index cf68bb611008ad8d7c9efbc93e8d4f057a937376..b2bc97f4744a5dc749ac2bed1dae58bf1efe5788 100644 (file)
@@ -1,12 +1,3 @@
-// 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.
-
 #![warn(clippy::all)]
 
 use std::cmp::max as my_max;
@@ -15,9 +6,20 @@
 
 const LARGE: usize = 3;
 
+struct NotOrd(u64);
+
+impl NotOrd {
+    fn min(self, x: u64) -> NotOrd {
+        NotOrd(x)
+    }
+
+    fn max(self, x: u64) -> NotOrd {
+        NotOrd(x)
+    }
+}
+
 fn main() {
-    let x;
-    x = 2usize;
+    let x = 2usize;
     min(1, max(3, x));
     min(max(3, x), 1);
     max(min(x, 1), 3);
@@ -32,11 +34,29 @@ fn main() {
     let y = 2isize;
     min(max(y, -1), 3);
 
-    let s;
-    s = "Hello";
-
+    let s = "Hello";
     min("Apple", max("Zoo", s));
     max(min(s, "Apple"), "Zoo");
 
     max("Apple", min(s, "Zoo")); // ok
+
+    let f = 3f32;
+    x.min(1).max(3);
+    x.max(3).min(1);
+    f.max(3f32).min(1f32);
+
+    x.max(1).min(3); // ok
+    x.min(3).max(1); // ok
+    f.min(3f32).max(1f32); // ok
+
+    max(x.min(1), 3);
+    min(x.max(1), 3); // ok
+
+    s.max("Zoo").min("Apple");
+    s.min("Apple").max("Zoo");
+
+    s.min("Zoo").max("Apple"); // ok
+
+    let not_ord = NotOrd(1);
+    not_ord.min(1).max(3); // ok
 }