about summary refs log tree commit diff
path: root/src/libcore/cmp.rs
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-04-01 22:32:37 -0700
committerNiko Matsakis <niko@alum.mit.edu>2013-04-10 07:52:46 -0700
commit3322595e896e95c3e19ca33c854ad529f2ef3c19 (patch)
treef785d8bc645c7fa424ef1487e617e054415f883d /src/libcore/cmp.rs
parent5606fc0c90461db40faeca16d7bffd9e61c2be73 (diff)
downloadrust-3322595e896e95c3e19ca33c854ad529f2ef3c19.tar.gz
rust-3322595e896e95c3e19ca33c854ad529f2ef3c19.zip
Reason about nested free variables that appear in a function
signature.  In a nutshell, the idea is to (1) report an error if, for
a region pointer `'a T`, the lifetime `'a` is longer than any
lifetimes that appear in `T` (in other words, if a borrowed pointer
outlives any portion of its contents) and then (2) use this to assume
that in a function like `fn(self: &'a &'b T)`, the relationship `'a <=
'b` holds. This is needed for #5656.  Fixes #5728.
Diffstat (limited to 'src/libcore/cmp.rs')
-rw-r--r--src/libcore/cmp.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs
index f96575aaf41..bd4832b6faf 100644
--- a/src/libcore/cmp.rs
+++ b/src/libcore/cmp.rs
@@ -116,6 +116,19 @@ totalord_impl!(i64)
 totalord_impl!(int)
 totalord_impl!(uint)
 
+pub fn cmp2<A:TotalOrd,B:TotalOrd>(
+    a1: &A, b1: &B,
+    a2: &A, b2: &B) -> Ordering
+{
+    //! Compares (a1, b1) against (a2, b2), where the a values are more significant.
+
+    match a1.cmp(a2) {
+        Less => Less,
+        Greater => Greater,
+        Equal => b1.cmp(b2)
+    }
+}
+
 /**
 * Trait for values that can be compared for a sort-order.
 *
@@ -194,6 +207,14 @@ mod test {
     }
 
     #[test]
+    fn test_cmp2() {
+        assert_eq!(cmp2(1, 2, 3, 4), Less);
+        assert_eq!(cmp2(3, 2, 3, 4), Less);
+        assert_eq!(cmp2(5, 2, 3, 4), Greater);
+        assert_eq!(cmp2(5, 5, 5, 4), Greater);
+    }
+
+    #[test]
     fn test_int_totaleq() {
         assert!(5.equals(&5));
         assert!(!2.equals(&17));