Use private trait for Rc/Arc Eq specialization
This commit is contained in:
parent
2a916a617f
commit
40d60a4608
2 changed files with 74 additions and 37 deletions
|
@ -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<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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue