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/sync.rs | |
| parent | 2a916a617f6c6c62536a3b164f4b15ea58eaa148 (diff) | |
| download | rust-40d60a4608c76e8a74ab643f4629dbaf129e07a4.tar.gz rust-40d60a4608c76e8a74ab643f4629dbaf129e07a4.zip | |
Use private trait for Rc/Arc Eq specialization
Diffstat (limited to 'src/liballoc/sync.rs')
| -rw-r--r-- | src/liballoc/sync.rs | 54 |
1 files changed, 37 insertions, 17 deletions
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. |
