about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorP1start <rewi-github@whanau.org>2015-05-16 10:29:35 +1200
committerP1start <rewi-github@whanau.org>2015-05-16 11:01:52 +1200
commitfa28642de9fc158613f294896e62e12c3067714e (patch)
treec2a56ac6f2bb16d01de2a3a1a1fd40b5fe5af7ca /src/liballoc
parent716f920b7e234b450f272346fea961832505c06e (diff)
downloadrust-fa28642de9fc158613f294896e62e12c3067714e.tar.gz
rust-fa28642de9fc158613f294896e62e12c3067714e.zip
Allow `?Sized` types in `Rc`’s impls of {Partial,}{Ord,Eq} and Borrow
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/rc.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index f2b83fdeefa..88c5c38172a 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -634,7 +634,18 @@ impl<T: Default> Default for Rc<T> {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
+#[cfg(stage0)]
 impl<T: PartialEq> PartialEq for Rc<T> {
+    #[inline(always)]
+    fn eq(&self, other: &Rc<T>) -> bool { **self == **other }
+
+    #[inline(always)]
+    fn ne(&self, other: &Rc<T>) -> bool { **self != **other }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[cfg(not(stage0))]
+impl<T: ?Sized + PartialEq> PartialEq for Rc<T> {
     /// Equality for two `Rc<T>`s.
     ///
     /// Two `Rc<T>`s are equal if their inner value are equal.
@@ -669,10 +680,35 @@ impl<T: PartialEq> PartialEq for Rc<T> {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
+#[cfg(stage0)]
 impl<T: Eq> Eq for Rc<T> {}
+#[stable(feature = "rust1", since = "1.0.0")]
+#[cfg(not(stage0))]
+impl<T: ?Sized + Eq> Eq for Rc<T> {}
 
 #[stable(feature = "rust1", since = "1.0.0")]
+#[cfg(stage0)]
 impl<T: PartialOrd> PartialOrd for Rc<T> {
+    #[inline(always)]
+    fn partial_cmp(&self, other: &Rc<T>) -> Option<Ordering> {
+        (**self).partial_cmp(&**other)
+    }
+
+    #[inline(always)]
+    fn lt(&self, other: &Rc<T>) -> bool { **self < **other }
+
+    #[inline(always)]
+    fn le(&self, other: &Rc<T>) -> bool { **self <= **other }
+
+    #[inline(always)]
+    fn gt(&self, other: &Rc<T>) -> bool { **self > **other }
+
+    #[inline(always)]
+    fn ge(&self, other: &Rc<T>) -> bool { **self >= **other }
+}
+#[stable(feature = "rust1", since = "1.0.0")]
+#[cfg(not(stage0))]
+impl<T: ?Sized + PartialOrd> PartialOrd for Rc<T> {
     /// Partial comparison for two `Rc<T>`s.
     ///
     /// The two are compared by calling `partial_cmp()` on their inner values.
@@ -757,7 +793,14 @@ impl<T: PartialOrd> PartialOrd for Rc<T> {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
+#[cfg(stage0)]
 impl<T: Ord> Ord for Rc<T> {
+    #[inline]
+    fn cmp(&self, other: &Rc<T>) -> Ordering { (**self).cmp(&**other) }
+}
+#[stable(feature = "rust1", since = "1.0.0")]
+#[cfg(not(stage0))]
+impl<T: ?Sized + Ord> Ord for Rc<T> {
     /// Comparison for two `Rc<T>`s.
     ///
     /// The two are compared by calling `cmp()` on their inner values.
@@ -1399,4 +1442,9 @@ mod tests {
         assert_eq!(format!("{:?}", foo), "75");
     }
 
+    #[test]
+    fn test_unsized() {
+        let foo: Rc<[i32]> = Rc::new([1, 2, 3]);
+        assert_eq!(foo, foo.clone());
+    }
 }