diff options
| author | Thomas Heck <t@b128.net> | 2018-12-05 21:43:44 +0100 |
|---|---|---|
| committer | Thomas Heck <t@b128.net> | 2018-12-08 13:30:54 +0100 |
| commit | 40d60a4608c76e8a74ab643f4629dbaf129e07a4 (patch) | |
| tree | b8f88a5acaeb69a364f06bbb7d1958a03cafed6d /src/liballoc | |
| parent | 2a916a617f6c6c62536a3b164f4b15ea58eaa148 (diff) | |
| download | rust-40d60a4608c76e8a74ab643f4629dbaf129e07a4.tar.gz rust-40d60a4608c76e8a74ab643f4629dbaf129e07a4.zip | |
Use private trait for Rc/Arc Eq specialization
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/rc.rs | 57 | ||||
| -rw-r--r-- | src/liballoc/sync.rs | 54 |
2 files changed, 74 insertions, 37 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 85bde5f63ce..6769a70ddbe 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -8,7 +8,6 @@ // 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 @@ -902,6 +901,38 @@ impl<T: Default> Default for Rc<T> { } #[stable(feature = "rust1", since = "1.0.0")] +trait RcEqIdent<T: ?Sized + PartialEq> { + fn eq(&self, other: &Rc<T>) -> bool; + fn ne(&self, other: &Rc<T>) -> bool; +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: ?Sized + PartialEq> RcEqIdent<T> for Rc<T> { + #[inline] + default fn eq(&self, other: &Rc<T>) -> bool { + **self == **other + } + + #[inline] + default fn ne(&self, other: &Rc<T>) -> bool { + **self != **other + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: ?Sized + Eq> RcEqIdent<T> for Rc<T> { + #[inline] + fn eq(&self, other: &Rc<T>) -> bool { + Rc::ptr_eq(self, other) || **self == **other + } + + #[inline] + fn ne(&self, other: &Rc<T>) -> bool { + !Rc::ptr_eq(self, other) && **self != **other + } +} + +#[stable(feature = "rust1", since = "1.0.0")] impl<T: ?Sized + PartialEq> PartialEq for Rc<T> { /// Equality for two `Rc`s. /// @@ -919,9 +950,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Rc<T> { /// /// assert!(five == Rc::new(5)); /// ``` - #[inline(always)] - default fn eq(&self, other: &Rc<T>) -> bool { - **self == **other + #[inline] + fn eq(&self, other: &Rc<T>) -> bool { + RcEqIdent::eq(self, other) } /// Inequality for two `Rc`s. @@ -940,23 +971,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Rc<T> { /// /// assert!(five != Rc::new(6)); /// ``` - #[inline(always)] - default fn ne(&self, other: &Rc<T>) -> bool { - **self != **other - } -} - -#[doc(hidden)] -#[stable(feature = "rust1", since = "1.0.0")] -impl<T: ?Sized + Eq> PartialEq for Rc<T> { - #[inline(always)] - fn eq(&self, other: &Rc<T>) -> bool { - Rc::ptr_eq(self, other) || **self == **other - } - - #[inline(always)] + #[inline] fn ne(&self, other: &Rc<T>) -> bool { - !Rc::ptr_eq(self, other) && **self != **other + RcEqIdent::ne(self, other) } } diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index d6863238cd4..e596694fb9d 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -8,7 +8,6 @@ // 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. @@ -1289,6 +1288,37 @@ impl<T: ?Sized> Drop for Weak<T> { } #[stable(feature = "rust1", since = "1.0.0")] +trait ArcEqIdent<T: ?Sized + PartialEq> { + fn eq(&self, other: &Arc<T>) -> bool; + fn ne(&self, other: &Arc<T>) -> bool; +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: ?Sized + PartialEq> ArcEqIdent<T> for Arc<T> { + #[inline] + default fn eq(&self, other: &Arc<T>) -> bool { + **self == **other + } + #[inline] + default fn ne(&self, other: &Arc<T>) -> bool { + **self != **other + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: ?Sized + Eq> ArcEqIdent<T> for Arc<T> { + #[inline] + fn eq(&self, other: &Arc<T>) -> bool { + Arc::ptr_eq(self, other) || **self == **other + } + + #[inline] + fn ne(&self, other: &Arc<T>) -> bool { + !Arc::ptr_eq(self, other) && **self != **other + } +} + +#[stable(feature = "rust1", since = "1.0.0")] impl<T: ?Sized + PartialEq> PartialEq for Arc<T> { /// Equality for two `Arc`s. /// @@ -1306,8 +1336,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> { /// /// assert!(five == Arc::new(5)); /// ``` - default fn eq(&self, other: &Arc<T>) -> bool { - **self == **other + #[inline] + fn eq(&self, other: &Arc<T>) -> bool { + ArcEqIdent::eq(self, other) } /// Inequality for two `Arc`s. @@ -1326,23 +1357,12 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> { /// /// assert!(five != Arc::new(6)); /// ``` - default fn ne(&self, other: &Arc<T>) -> bool { - **self != **other - } -} -#[doc(hidden)] -#[stable(feature = "rust1", since = "1.0.0")] -impl<T: ?Sized + Eq> PartialEq for Arc<T> { - #[inline(always)] - fn eq(&self, other: &Arc<T>) -> bool { - Arc::ptr_eq(self, other) || **self == **other - } - - #[inline(always)] + #[inline] fn ne(&self, other: &Arc<T>) -> bool { - !Arc::ptr_eq(self, other) && **self != **other + ArcEqIdent::ne(self, other) } } + #[stable(feature = "rust1", since = "1.0.0")] impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> { /// Partial comparison for two `Arc`s. |
