From 40d60a4608c76e8a74ab643f4629dbaf129e07a4 Mon Sep 17 00:00:00 2001 From: Thomas Heck Date: Wed, 5 Dec 2018 21:43:44 +0100 Subject: Use private trait for Rc/Arc Eq specialization --- src/liballoc/rc.rs | 57 ++++++++++++++++++++++++++++++++++------------------ src/liballoc/sync.rs | 54 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 74 insertions(+), 37 deletions(-) (limited to 'src/liballoc') 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 @@ -901,6 +900,38 @@ impl Default for Rc { } } +#[stable(feature = "rust1", since = "1.0.0")] +trait RcEqIdent { + fn eq(&self, other: &Rc) -> bool; + fn ne(&self, other: &Rc) -> bool; +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl RcEqIdent for Rc { + #[inline] + default fn eq(&self, other: &Rc) -> bool { + **self == **other + } + + #[inline] + default fn ne(&self, other: &Rc) -> bool { + **self != **other + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl RcEqIdent for Rc { + #[inline] + fn eq(&self, other: &Rc) -> bool { + Rc::ptr_eq(self, other) || **self == **other + } + + #[inline] + fn ne(&self, other: &Rc) -> bool { + !Rc::ptr_eq(self, other) && **self != **other + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl PartialEq for Rc { /// Equality for two `Rc`s. @@ -919,9 +950,9 @@ impl PartialEq for Rc { /// /// assert!(five == Rc::new(5)); /// ``` - #[inline(always)] - default fn eq(&self, other: &Rc) -> bool { - **self == **other + #[inline] + fn eq(&self, other: &Rc) -> bool { + RcEqIdent::eq(self, other) } /// Inequality for two `Rc`s. @@ -940,23 +971,9 @@ impl PartialEq for Rc { /// /// assert!(five != Rc::new(6)); /// ``` - #[inline(always)] - 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)] + #[inline] fn ne(&self, other: &Rc) -> 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. @@ -1288,6 +1287,37 @@ impl Drop for Weak { } } +#[stable(feature = "rust1", since = "1.0.0")] +trait ArcEqIdent { + fn eq(&self, other: &Arc) -> bool; + fn ne(&self, other: &Arc) -> bool; +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl ArcEqIdent for Arc { + #[inline] + default fn eq(&self, other: &Arc) -> bool { + **self == **other + } + #[inline] + default fn ne(&self, other: &Arc) -> bool { + **self != **other + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl ArcEqIdent for Arc { + #[inline] + fn eq(&self, other: &Arc) -> bool { + Arc::ptr_eq(self, other) || **self == **other + } + + #[inline] + fn ne(&self, other: &Arc) -> bool { + !Arc::ptr_eq(self, other) && **self != **other + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl PartialEq for Arc { /// Equality for two `Arc`s. @@ -1306,8 +1336,9 @@ impl PartialEq for Arc { /// /// assert!(five == Arc::new(5)); /// ``` - default fn eq(&self, other: &Arc) -> bool { - **self == **other + #[inline] + fn eq(&self, other: &Arc) -> bool { + ArcEqIdent::eq(self, other) } /// Inequality for two `Arc`s. @@ -1326,23 +1357,12 @@ impl PartialEq for Arc { /// /// assert!(five != Arc::new(6)); /// ``` - 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)] + #[inline] fn ne(&self, other: &Arc) -> bool { - !Arc::ptr_eq(self, other) && **self != **other + ArcEqIdent::ne(self, other) } } + #[stable(feature = "rust1", since = "1.0.0")] impl PartialOrd for Arc { /// Partial comparison for two `Arc`s. -- cgit 1.4.1-3-g733a5