Skip to content

Commit 40d60a4

Browse files
committed
Use private trait for Rc/Arc Eq specialization
1 parent 2a916a6 commit 40d60a4

File tree

2 files changed

+74
-37
lines changed

2 files changed

+74
-37
lines changed

src/liballoc/rc.rs

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(specialization)]
1211
#![allow(deprecated)]
1312

1413
//! Single-threaded reference-counting pointers. 'Rc' stands for 'Reference
@@ -901,6 +900,38 @@ impl<T: Default> Default for Rc<T> {
901900
}
902901
}
903902

903+
#[stable(feature = "rust1", since = "1.0.0")]
904+
trait RcEqIdent<T: ?Sized + PartialEq> {
905+
fn eq(&self, other: &Rc<T>) -> bool;
906+
fn ne(&self, other: &Rc<T>) -> bool;
907+
}
908+
909+
#[stable(feature = "rust1", since = "1.0.0")]
910+
impl<T: ?Sized + PartialEq> RcEqIdent<T> for Rc<T> {
911+
#[inline]
912+
default fn eq(&self, other: &Rc<T>) -> bool {
913+
**self == **other
914+
}
915+
916+
#[inline]
917+
default fn ne(&self, other: &Rc<T>) -> bool {
918+
**self != **other
919+
}
920+
}
921+
922+
#[stable(feature = "rust1", since = "1.0.0")]
923+
impl<T: ?Sized + Eq> RcEqIdent<T> for Rc<T> {
924+
#[inline]
925+
fn eq(&self, other: &Rc<T>) -> bool {
926+
Rc::ptr_eq(self, other) || **self == **other
927+
}
928+
929+
#[inline]
930+
fn ne(&self, other: &Rc<T>) -> bool {
931+
!Rc::ptr_eq(self, other) && **self != **other
932+
}
933+
}
934+
904935
#[stable(feature = "rust1", since = "1.0.0")]
905936
impl<T: ?Sized + PartialEq> PartialEq for Rc<T> {
906937
/// Equality for two `Rc`s.
@@ -919,9 +950,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Rc<T> {
919950
///
920951
/// assert!(five == Rc::new(5));
921952
/// ```
922-
#[inline(always)]
923-
default fn eq(&self, other: &Rc<T>) -> bool {
924-
**self == **other
953+
#[inline]
954+
fn eq(&self, other: &Rc<T>) -> bool {
955+
RcEqIdent::eq(self, other)
925956
}
926957

927958
/// Inequality for two `Rc`s.
@@ -940,23 +971,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Rc<T> {
940971
///
941972
/// assert!(five != Rc::new(6));
942973
/// ```
943-
#[inline(always)]
944-
default fn ne(&self, other: &Rc<T>) -> bool {
945-
**self != **other
946-
}
947-
}
948-
949-
#[doc(hidden)]
950-
#[stable(feature = "rust1", since = "1.0.0")]
951-
impl<T: ?Sized + Eq> PartialEq for Rc<T> {
952-
#[inline(always)]
953-
fn eq(&self, other: &Rc<T>) -> bool {
954-
Rc::ptr_eq(self, other) || **self == **other
955-
}
956-
957-
#[inline(always)]
974+
#[inline]
958975
fn ne(&self, other: &Rc<T>) -> bool {
959-
!Rc::ptr_eq(self, other) && **self != **other
976+
RcEqIdent::ne(self, other)
960977
}
961978
}
962979

src/liballoc/sync.rs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(specialization)]
1211
#![stable(feature = "rust1", since = "1.0.0")]
1312

1413
//! Thread-safe reference-counting pointers.
@@ -1288,6 +1287,37 @@ impl<T: ?Sized> Drop for Weak<T> {
12881287
}
12891288
}
12901289

1290+
#[stable(feature = "rust1", since = "1.0.0")]
1291+
trait ArcEqIdent<T: ?Sized + PartialEq> {
1292+
fn eq(&self, other: &Arc<T>) -> bool;
1293+
fn ne(&self, other: &Arc<T>) -> bool;
1294+
}
1295+
1296+
#[stable(feature = "rust1", since = "1.0.0")]
1297+
impl<T: ?Sized + PartialEq> ArcEqIdent<T> for Arc<T> {
1298+
#[inline]
1299+
default fn eq(&self, other: &Arc<T>) -> bool {
1300+
**self == **other
1301+
}
1302+
#[inline]
1303+
default fn ne(&self, other: &Arc<T>) -> bool {
1304+
**self != **other
1305+
}
1306+
}
1307+
1308+
#[stable(feature = "rust1", since = "1.0.0")]
1309+
impl<T: ?Sized + Eq> ArcEqIdent<T> for Arc<T> {
1310+
#[inline]
1311+
fn eq(&self, other: &Arc<T>) -> bool {
1312+
Arc::ptr_eq(self, other) || **self == **other
1313+
}
1314+
1315+
#[inline]
1316+
fn ne(&self, other: &Arc<T>) -> bool {
1317+
!Arc::ptr_eq(self, other) && **self != **other
1318+
}
1319+
}
1320+
12911321
#[stable(feature = "rust1", since = "1.0.0")]
12921322
impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
12931323
/// Equality for two `Arc`s.
@@ -1306,8 +1336,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
13061336
///
13071337
/// assert!(five == Arc::new(5));
13081338
/// ```
1309-
default fn eq(&self, other: &Arc<T>) -> bool {
1310-
**self == **other
1339+
#[inline]
1340+
fn eq(&self, other: &Arc<T>) -> bool {
1341+
ArcEqIdent::eq(self, other)
13111342
}
13121343

13131344
/// Inequality for two `Arc`s.
@@ -1326,23 +1357,12 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
13261357
///
13271358
/// assert!(five != Arc::new(6));
13281359
/// ```
1329-
default fn ne(&self, other: &Arc<T>) -> bool {
1330-
**self != **other
1331-
}
1332-
}
1333-
#[doc(hidden)]
1334-
#[stable(feature = "rust1", since = "1.0.0")]
1335-
impl<T: ?Sized + Eq> PartialEq for Arc<T> {
1336-
#[inline(always)]
1337-
fn eq(&self, other: &Arc<T>) -> bool {
1338-
Arc::ptr_eq(self, other) || **self == **other
1339-
}
1340-
1341-
#[inline(always)]
1360+
#[inline]
13421361
fn ne(&self, other: &Arc<T>) -> bool {
1343-
!Arc::ptr_eq(self, other) && **self != **other
1362+
ArcEqIdent::ne(self, other)
13441363
}
13451364
}
1365+
13461366
#[stable(feature = "rust1", since = "1.0.0")]
13471367
impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
13481368
/// Partial comparison for two `Arc`s.

0 commit comments

Comments
 (0)