Skip to content

Commit 5e535ea

Browse files
committed
Auto merge of #25460 - P1start:rc-unsized-impls, r=luqmana
Most of `Rc`’s trait implementations were DST-ified in #24619, but not these ones.
2 parents 63b000b + fa28642 commit 5e535ea

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/liballoc/rc.rs

+48
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,18 @@ impl<T: Default> Default for Rc<T> {
634634
}
635635

636636
#[stable(feature = "rust1", since = "1.0.0")]
637+
#[cfg(stage0)]
637638
impl<T: PartialEq> PartialEq for Rc<T> {
639+
#[inline(always)]
640+
fn eq(&self, other: &Rc<T>) -> bool { **self == **other }
641+
642+
#[inline(always)]
643+
fn ne(&self, other: &Rc<T>) -> bool { **self != **other }
644+
}
645+
646+
#[stable(feature = "rust1", since = "1.0.0")]
647+
#[cfg(not(stage0))]
648+
impl<T: ?Sized + PartialEq> PartialEq for Rc<T> {
638649
/// Equality for two `Rc<T>`s.
639650
///
640651
/// Two `Rc<T>`s are equal if their inner value are equal.
@@ -669,10 +680,35 @@ impl<T: PartialEq> PartialEq for Rc<T> {
669680
}
670681

671682
#[stable(feature = "rust1", since = "1.0.0")]
683+
#[cfg(stage0)]
672684
impl<T: Eq> Eq for Rc<T> {}
685+
#[stable(feature = "rust1", since = "1.0.0")]
686+
#[cfg(not(stage0))]
687+
impl<T: ?Sized + Eq> Eq for Rc<T> {}
673688

674689
#[stable(feature = "rust1", since = "1.0.0")]
690+
#[cfg(stage0)]
675691
impl<T: PartialOrd> PartialOrd for Rc<T> {
692+
#[inline(always)]
693+
fn partial_cmp(&self, other: &Rc<T>) -> Option<Ordering> {
694+
(**self).partial_cmp(&**other)
695+
}
696+
697+
#[inline(always)]
698+
fn lt(&self, other: &Rc<T>) -> bool { **self < **other }
699+
700+
#[inline(always)]
701+
fn le(&self, other: &Rc<T>) -> bool { **self <= **other }
702+
703+
#[inline(always)]
704+
fn gt(&self, other: &Rc<T>) -> bool { **self > **other }
705+
706+
#[inline(always)]
707+
fn ge(&self, other: &Rc<T>) -> bool { **self >= **other }
708+
}
709+
#[stable(feature = "rust1", since = "1.0.0")]
710+
#[cfg(not(stage0))]
711+
impl<T: ?Sized + PartialOrd> PartialOrd for Rc<T> {
676712
/// Partial comparison for two `Rc<T>`s.
677713
///
678714
/// The two are compared by calling `partial_cmp()` on their inner values.
@@ -757,7 +793,14 @@ impl<T: PartialOrd> PartialOrd for Rc<T> {
757793
}
758794

759795
#[stable(feature = "rust1", since = "1.0.0")]
796+
#[cfg(stage0)]
760797
impl<T: Ord> Ord for Rc<T> {
798+
#[inline]
799+
fn cmp(&self, other: &Rc<T>) -> Ordering { (**self).cmp(&**other) }
800+
}
801+
#[stable(feature = "rust1", since = "1.0.0")]
802+
#[cfg(not(stage0))]
803+
impl<T: ?Sized + Ord> Ord for Rc<T> {
761804
/// Comparison for two `Rc<T>`s.
762805
///
763806
/// The two are compared by calling `cmp()` on their inner values.
@@ -1399,4 +1442,9 @@ mod tests {
13991442
assert_eq!(format!("{:?}", foo), "75");
14001443
}
14011444

1445+
#[test]
1446+
fn test_unsized() {
1447+
let foo: Rc<[i32]> = Rc::new([1, 2, 3]);
1448+
assert_eq!(foo, foo.clone());
1449+
}
14021450
}

src/libcollections/borrow.rs

+6
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,16 @@ impl<'a, T: ?Sized> BorrowMut<T> for &'a mut T {
116116
fn borrow_mut(&mut self) -> &mut T { &mut **self }
117117
}
118118

119+
#[cfg(stage0)]
119120
impl<T> Borrow<T> for rc::Rc<T> {
120121
fn borrow(&self) -> &T { &**self }
121122
}
122123

124+
#[cfg(not(stage0))]
125+
impl<T: ?Sized> Borrow<T> for rc::Rc<T> {
126+
fn borrow(&self) -> &T { &**self }
127+
}
128+
123129
impl<T> Borrow<T> for arc::Arc<T> {
124130
fn borrow(&self) -> &T { &**self }
125131
}

0 commit comments

Comments
 (0)