Skip to content

Commit 448d2a8

Browse files
authored
Rollup merge of #112628 - gootorov:box_alloc_partialeq, r=joshtriplett
Allow comparing `Box`es with different allocators Currently, comparing `Box`es over different allocators is not allowed: ```Rust error[E0308]: mismatched types --> library/alloc/tests/boxed.rs:22:20 | 22 | assert_eq!(b1, b2); | ^^ expected `Box<{integer}, ConstAllocator>`, found `Box<{integer}, AnotherAllocator>` | = note: expected struct `Box<{integer}, ConstAllocator>` found struct `Box<{integer}, AnotherAllocator>` For more information about this error, try `rustc --explain E0308`. error: could not compile `alloc` (test "collectionstests") due to previous error ``` This PR lifts this limitation
2 parents 353dd71 + 001b081 commit 448d2a8

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

library/alloc/src/boxed.rs

+26-9
Original file line numberDiff line numberDiff line change
@@ -1319,39 +1319,56 @@ impl Clone for Box<str> {
13191319
}
13201320

13211321
#[stable(feature = "rust1", since = "1.0.0")]
1322-
impl<T: ?Sized + PartialEq, A: Allocator> PartialEq for Box<T, A> {
1322+
impl<T, A1, A2> PartialEq<Box<T, A2>> for Box<T, A1>
1323+
where
1324+
T: ?Sized + PartialEq,
1325+
A1: Allocator,
1326+
A2: Allocator,
1327+
{
13231328
#[inline]
1324-
fn eq(&self, other: &Self) -> bool {
1329+
fn eq(&self, other: &Box<T, A2>) -> bool {
13251330
PartialEq::eq(&**self, &**other)
13261331
}
1332+
13271333
#[inline]
1328-
fn ne(&self, other: &Self) -> bool {
1334+
fn ne(&self, other: &Box<T, A2>) -> bool {
13291335
PartialEq::ne(&**self, &**other)
13301336
}
13311337
}
1338+
13321339
#[stable(feature = "rust1", since = "1.0.0")]
1333-
impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Box<T, A> {
1340+
impl<T, A1, A2> PartialOrd<Box<T, A2>> for Box<T, A1>
1341+
where
1342+
T: ?Sized + PartialOrd,
1343+
A1: Allocator,
1344+
A2: Allocator,
1345+
{
13341346
#[inline]
1335-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
1347+
fn partial_cmp(&self, other: &Box<T, A2>) -> Option<Ordering> {
13361348
PartialOrd::partial_cmp(&**self, &**other)
13371349
}
1350+
13381351
#[inline]
1339-
fn lt(&self, other: &Self) -> bool {
1352+
fn lt(&self, other: &Box<T, A2>) -> bool {
13401353
PartialOrd::lt(&**self, &**other)
13411354
}
1355+
13421356
#[inline]
1343-
fn le(&self, other: &Self) -> bool {
1357+
fn le(&self, other: &Box<T, A2>) -> bool {
13441358
PartialOrd::le(&**self, &**other)
13451359
}
1360+
13461361
#[inline]
1347-
fn ge(&self, other: &Self) -> bool {
1362+
fn ge(&self, other: &Box<T, A2>) -> bool {
13481363
PartialOrd::ge(&**self, &**other)
13491364
}
1365+
13501366
#[inline]
1351-
fn gt(&self, other: &Self) -> bool {
1367+
fn gt(&self, other: &Box<T, A2>) -> bool {
13521368
PartialOrd::gt(&**self, &**other)
13531369
}
13541370
}
1371+
13551372
#[stable(feature = "rust1", since = "1.0.0")]
13561373
impl<T: ?Sized + Ord, A: Allocator> Ord for Box<T, A> {
13571374
#[inline]

0 commit comments

Comments
 (0)