diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 7c51c4b161ca8..9c018b240d076 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(specialization)] #![stable(feature = "rust1", since = "1.0.0")] //! Thread-safe reference-counting pointers. @@ -1018,6 +1019,9 @@ impl PartialEq for Arc { /// /// Two `Arc`s are equal if their inner values are equal. /// + /// If `T` also implements `Eq`, two `Arc`s that point to the same value are + /// always equal. + /// /// # Examples /// /// ``` @@ -1027,7 +1031,7 @@ impl PartialEq for Arc { /// /// assert!(five == Arc::new(5)); /// ``` - fn eq(&self, other: &Arc) -> bool { + default fn eq(&self, other: &Arc) -> bool { *(*self) == *(*other) } @@ -1035,6 +1039,9 @@ impl PartialEq for Arc { /// /// Two `Arc`s are unequal if their inner values are unequal. /// + /// If `T` also implements `Eq`, two `Arc`s that point to the same value are + /// never unequal. + /// /// # Examples /// /// ``` @@ -1044,10 +1051,23 @@ impl PartialEq for Arc { /// /// assert!(five != Arc::new(6)); /// ``` - fn ne(&self, other: &Arc) -> bool { + default fn ne(&self, other: &Arc) -> bool { *(*self) != *(*other) } } +#[doc(hidden)] +#[stable(feature = "rust1", since = "1.0.0")] +impl PartialEq for Arc { + #[inline(always)] + fn eq(&self, other: &Arc) -> bool { + Arc::ptr_eq(self, other) || *(*self) == *(*other) + } + + #[inline(always)] + fn ne(&self, other: &Arc) -> bool { + !Arc::ptr_eq(self, other) && *(*self) != *(*other) + } +} #[stable(feature = "rust1", since = "1.0.0")] impl PartialOrd for Arc { /// Partial comparison for two `Arc`s. diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 94fe36d01a5a5..6708b8256f4f3 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(specialization)] #![allow(deprecated)] //! Single-threaded reference-counting pointers. 'Rc' stands for 'Reference @@ -773,6 +774,9 @@ impl PartialEq for Rc { /// /// Two `Rc`s are equal if their inner values are equal. /// + /// If `T` also implements `Eq`, two `Rc`s that point to the same value are + /// always equal. + /// /// # Examples /// /// ``` @@ -783,7 +787,7 @@ impl PartialEq for Rc { /// assert!(five == Rc::new(5)); /// ``` #[inline(always)] - fn eq(&self, other: &Rc) -> bool { + default fn eq(&self, other: &Rc) -> bool { **self == **other } @@ -791,6 +795,9 @@ impl PartialEq for Rc { /// /// Two `Rc`s are unequal if their inner values are unequal. /// + /// If `T` also implements `Eq`, two `Rc`s that point to the same value are + /// never unequal. + /// /// # Examples /// /// ``` @@ -801,11 +808,25 @@ impl PartialEq for Rc { /// assert!(five != Rc::new(6)); /// ``` #[inline(always)] - fn ne(&self, other: &Rc) -> bool { + default fn ne(&self, other: &Rc) -> bool { **self != **other } } +#[doc(hidden)] +#[stable(feature = "rust1", since = "1.0.0")] +impl PartialEq for Rc { + #[inline(always)] + fn eq(&self, other: &Rc) -> bool { + Rc::ptr_eq(self, other) || **self == **other + } + + #[inline(always)] + fn ne(&self, other: &Rc) -> bool { + !Rc::ptr_eq(self, other) && **self != **other + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Eq for Rc {}