]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/min_max.rs
check impl Ord / is_float
[rust.git] / tests / ui / min_max.rs
index 9866933f9feb4d68b92008cff32591c182c61102..f7ed72a11cf684b64f8d584cbaa990ae4aa0fa39 100644 (file)
@@ -1,13 +1,22 @@
-#![feature(tool_lints)]
-
-
 #![warn(clippy::all)]
 
-use std::cmp::{min, max};
-use std::cmp::min as my_min;
 use std::cmp::max as my_max;
+use std::cmp::min as my_min;
+use std::cmp::{max, min};
+
+const LARGE: usize = 3;
+
+struct NotOrd(u64);
+
+impl NotOrd {
+    fn min(self, x: u64) -> NotOrd {
+        NotOrd(x)
+    }
 
-const LARGE : usize = 3;
+    fn max(self, x: u64) -> NotOrd {
+        NotOrd(x)
+    }
+}
 
 fn main() {
     let x;
@@ -33,4 +42,24 @@ fn main() {
     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
 }