From c162328d3070f4d7a018cf901e80ed8052f2e4a8 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 22 Jan 2025 18:06:08 +0000 Subject: [PATCH] aux: add `{Meta,Pointee}Sized` bounds to minicore With `MetaSized` bounds replacing `?Sized` and being added as a supertrait, the same relaxations applied to the standard library must be applied to minicore. --- tests/auxiliary/minicore.rs | 30 +++++------ .../traits/const-traits/auxiliary/minicore.rs | 50 +++++++++---------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs index 3a83b78529b4..db11549382fc 100644 --- a/tests/auxiliary/minicore.rs +++ b/tests/auxiliary/minicore.rs @@ -50,8 +50,8 @@ pub trait Sized: MetaSized {} #[lang = "legacy_receiver"] pub trait LegacyReceiver {} -impl LegacyReceiver for &T {} -impl LegacyReceiver for &mut T {} +impl LegacyReceiver for &T {} +impl LegacyReceiver for &mut T {} #[lang = "copy"] pub trait Copy: Sized {} @@ -73,14 +73,14 @@ impl_marker_trait!( f16, f32, f64, f128, ] ); -impl<'a, T: ?Sized> Copy for &'a T {} -impl Copy for *const T {} -impl Copy for *mut T {} +impl<'a, T: PointeeSized> Copy for &'a T {} +impl Copy for *const T {} +impl Copy for *mut T {} impl Copy for [T; N] {} #[lang = "phantom_data"] -pub struct PhantomData; -impl Copy for PhantomData {} +pub struct PhantomData; +impl Copy for PhantomData {} pub enum Option { None, @@ -96,17 +96,17 @@ impl Copy for Result {} #[lang = "manually_drop"] #[repr(transparent)] -pub struct ManuallyDrop { +pub struct ManuallyDrop { value: T, } -impl Copy for ManuallyDrop {} +impl Copy for ManuallyDrop {} #[lang = "unsafe_cell"] #[repr(transparent)] -pub struct UnsafeCell { +pub struct UnsafeCell { value: T, } -impl !Freeze for UnsafeCell {} +impl !Freeze for UnsafeCell {} #[lang = "tuple_trait"] pub trait Tuple {} @@ -182,15 +182,15 @@ pub trait Fn: FnMut { #[lang = "dispatch_from_dyn"] trait DispatchFromDyn {} -impl<'a, T: ?Sized + Unsize, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {} +impl<'a, T: PointeeSized + Unsize, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {} #[lang = "unsize"] -trait Unsize {} +trait Unsize: PointeeSized {} #[lang = "coerce_unsized"] -pub trait CoerceUnsized {} +pub trait CoerceUnsized {} -impl<'a, 'b: 'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} +impl<'a, 'b: 'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {} #[lang = "drop"] trait Drop { diff --git a/tests/ui/traits/const-traits/auxiliary/minicore.rs b/tests/ui/traits/const-traits/auxiliary/minicore.rs index 0a8a4bc097b8..073337b2ac6d 100644 --- a/tests/ui/traits/const-traits/auxiliary/minicore.rs +++ b/tests/ui/traits/const-traits/auxiliary/minicore.rs @@ -12,7 +12,7 @@ fundamental, marker_trait_attr, const_trait_impl, - const_destruct + const_destruct, )] #![allow(internal_features, incomplete_features)] #![no_std] @@ -32,7 +32,7 @@ pub trait Copy {} impl Copy for bool {} impl Copy for u8 {} -impl Copy for &T {} +impl Copy for &T {} #[lang = "add"] #[const_trait] @@ -113,17 +113,17 @@ pub trait Tuple {} #[lang = "legacy_receiver"] pub trait LegacyReceiver {} -impl LegacyReceiver for &T {} +impl LegacyReceiver for &T {} -impl LegacyReceiver for &mut T {} +impl LegacyReceiver for &mut T {} #[lang = "receiver"] pub trait Receiver { #[lang = "receiver_target"] - type Target: ?Sized; + type Target: MetaSized; } -impl Receiver for T { +impl Receiver for T { type Target = ::Target; } @@ -169,15 +169,15 @@ fn panic_fmt() {} #[lang = "index"] #[const_trait] -pub trait Index { - type Output: ?Sized; +pub trait Index { + type Output: MetaSized; fn index(&self, index: Idx) -> &Self::Output; } #[const_trait] -pub unsafe trait SliceIndex { - type Output: ?Sized; +pub unsafe trait SliceIndex { + type Output: MetaSized; fn index(self, slice: &T) -> &Self::Output; } @@ -206,23 +206,23 @@ where } #[lang = "unsize"] -pub trait Unsize {} +pub trait Unsize: PointeeSized {} #[lang = "coerce_unsized"] -pub trait CoerceUnsized {} +pub trait CoerceUnsized {} -impl<'a, 'b: 'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} +impl<'a, 'b: 'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {} #[lang = "deref"] #[const_trait] pub trait Deref { #[lang = "deref_target"] - type Target: ?Sized; + type Target: MetaSized; fn deref(&self) -> &Self::Target; } -impl const Deref for &T { +impl const Deref for &T { type Target = T; fn deref(&self) -> &T { @@ -230,7 +230,7 @@ impl const Deref for &T { } } -impl const Deref for &mut T { +impl const Deref for &mut T { type Target = T; fn deref(&self) -> &T { @@ -314,14 +314,14 @@ fn from_str(s: &str) -> Result { #[lang = "eq"] #[const_trait] -pub trait PartialEq { +pub trait PartialEq: PointeeSized { fn eq(&self, other: &Rhs) -> bool; fn ne(&self, other: &Rhs) -> bool { !self.eq(other) } } -impl const PartialEq<&B> for &A +impl const PartialEq<&B> for &A where A: ~const PartialEq, { @@ -364,7 +364,7 @@ impl

Pin

{ } } -impl<'a, T: ?Sized> Pin<&'a T> { +impl<'a, T: PointeeSized> Pin<&'a T> { const fn get_ref(self) -> &'a T { self.pointer } @@ -379,7 +379,7 @@ impl Pin

{ } } -impl<'a, T: ?Sized> Pin<&'a mut T> { +impl<'a, T: PointeeSized> Pin<&'a mut T> { const unsafe fn get_unchecked_mut(self) -> &'a mut T { self.pointer } @@ -425,7 +425,7 @@ impl Clone for RefCell { } } -struct RefCell { +struct RefCell { borrow: UnsafeCell<()>, value: UnsafeCell, } @@ -434,7 +434,7 @@ impl RefCell { loop {} } } -impl RefCell { +impl RefCell { fn borrow(&self) -> Ref<'_, T> { loop {} } @@ -442,16 +442,16 @@ impl RefCell { #[lang = "unsafe_cell"] #[repr(transparent)] -struct UnsafeCell { +struct UnsafeCell { value: T, } -struct Ref<'b, T: ?Sized + 'b> { +struct Ref<'b, T: PointeeSized + 'b> { value: *const T, borrow: &'b UnsafeCell<()>, } -impl Deref for Ref<'_, T> { +impl Deref for Ref<'_, T> { type Target = T; #[inline]