From 3c9a7491c2e2f54fa0ea59246c798017fcb8ce3f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 4 Jul 2023 04:05:44 -0400 Subject: [PATCH 1/2] Add a test for `PartialEq` across `Allocator`s breaking inference (#113283) Verify that `PartialEq` implementations do not break type inference when comparing types across different allocators. This catches a regression in current nightly introduced in 001b081cc1b (alloc: Allow comparing `Box`s over different allocators") `Box` is the only type that currently impelements this, but tests are included for `Rc` and `Arc` to prevent future regresssions. --- .../issue-113283-alllocator-trait-eq.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/ui/type-inference/issue-113283-alllocator-trait-eq.rs diff --git a/tests/ui/type-inference/issue-113283-alllocator-trait-eq.rs b/tests/ui/type-inference/issue-113283-alllocator-trait-eq.rs new file mode 100644 index 0000000000000..5d0e456d9ddc0 --- /dev/null +++ b/tests/ui/type-inference/issue-113283-alllocator-trait-eq.rs @@ -0,0 +1,18 @@ +// run-pass +// Verify that PartialEq implementations do not break type inference when +// accepting types with different allocators + +use std::rc::Rc; +use std::sync::Arc; + + +fn main() { + let boxed: Vec> = vec![]; + assert_eq!(boxed, vec![]); + + let rc: Vec> = vec![]; + assert_eq!(rc, vec![]); + + let arc: Vec> = vec![]; + assert_eq!(arc, vec![]); +} From a635bf7a3ba121b20993ed3f24300d2b81f7e5c1 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 4 Jul 2023 04:23:18 -0400 Subject: [PATCH 2/2] Revert "alloc: Allow comparing `Box`s over different allocators" This reverts commit 001b081cc1bfd24657e2dccbd9c8289f9a9d67a5. This change was done as the above commit introduces a regression in type inference. Regression test located at `tests/ui/type-inference/issue-113283-alllocator-trait-eq.rs` --- library/alloc/src/boxed.rs | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index fa23367593dbc..8ef2bac9282cd 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -1319,56 +1319,39 @@ impl Clone for Box { } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialEq> for Box -where - T: ?Sized + PartialEq, - A1: Allocator, - A2: Allocator, -{ +impl PartialEq for Box { #[inline] - fn eq(&self, other: &Box) -> bool { + fn eq(&self, other: &Self) -> bool { PartialEq::eq(&**self, &**other) } - #[inline] - fn ne(&self, other: &Box) -> bool { + fn ne(&self, other: &Self) -> bool { PartialEq::ne(&**self, &**other) } } - #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd> for Box -where - T: ?Sized + PartialOrd, - A1: Allocator, - A2: Allocator, -{ +impl PartialOrd for Box { #[inline] - fn partial_cmp(&self, other: &Box) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { PartialOrd::partial_cmp(&**self, &**other) } - #[inline] - fn lt(&self, other: &Box) -> bool { + fn lt(&self, other: &Self) -> bool { PartialOrd::lt(&**self, &**other) } - #[inline] - fn le(&self, other: &Box) -> bool { + fn le(&self, other: &Self) -> bool { PartialOrd::le(&**self, &**other) } - #[inline] - fn ge(&self, other: &Box) -> bool { + fn ge(&self, other: &Self) -> bool { PartialOrd::ge(&**self, &**other) } - #[inline] - fn gt(&self, other: &Box) -> bool { + fn gt(&self, other: &Self) -> bool { PartialOrd::gt(&**self, &**other) } } - #[stable(feature = "rust1", since = "1.0.0")] impl Ord for Box { #[inline]