From cc0ddbf31d008e8d5c200c593c822cd6621b3d89 Mon Sep 17 00:00:00 2001 From: Yosh Date: Wed, 30 Jul 2025 02:16:46 +0200 Subject: [PATCH 01/12] Add a `Move` marker trait impl Move for more types --- library/alloc/src/boxed.rs | 5 ++++- library/alloc/src/collections/btree/map.rs | 3 +++ library/alloc/src/collections/vec_deque/mod.rs | 3 +++ library/alloc/src/lib.rs | 1 + library/alloc/src/rc.rs | 5 ++++- library/alloc/src/sync.rs | 4 +++- library/alloc/src/vec/mod.rs | 5 ++++- library/core/src/marker.rs | 16 ++++++++++++++++ library/std/src/collections/hash/map.rs | 9 +++++++++ library/std/src/collections/hash/set.rs | 8 ++++++++ library/std/src/lib.rs | 1 + 11 files changed, 56 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 3db37f1d16f3d..e05fadc69ddb8 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -191,7 +191,7 @@ use core::error::{self, Error}; use core::fmt; use core::future::Future; use core::hash::{Hash, Hasher}; -use core::marker::{Tuple, Unsize}; +use core::marker::{Tuple, Move, Unsize}; use core::mem::{self, SizedTypeProperties}; use core::ops::{ AsyncFn, AsyncFnMut, AsyncFnOnce, CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut, @@ -2132,3 +2132,6 @@ impl Error for Box { Error::provide(&**self, request); } } + +#[unstable(feature = "move_trait", issue = "none")] +unsafe impl Move for Box {} diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 17c16e4aafff7..6233d6e4792bd 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -190,6 +190,9 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V, A: Allocator + Clone> Drop for BTr } } +#[unstable(feature = "move_trait", issue = "none")] +unsafe impl core::marker::Move for BTreeMap {} + // FIXME: This implementation is "wrong", but changing it would be a breaking change. // (The bounds of the automatic `UnwindSafe` implementation have been like this since Rust 1.50.) // Maybe we can fix it nonetheless with a crater run, or if the `UnwindSafe` diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 08b1828ff000e..09e84d3fab507 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -3025,6 +3025,9 @@ impl IndexMut for VecDeque { } } +#[unstable(feature = "move_trait", issue = "none")] +unsafe impl core::marker::Move for VecDeque {} + #[stable(feature = "rust1", since = "1.0.0")] impl FromIterator for VecDeque { #[track_caller] diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index c091e496c5090..b0d1da162b4c0 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -132,6 +132,7 @@ #![feature(local_waker)] #![feature(maybe_uninit_slice)] #![feature(maybe_uninit_uninit_array_transpose)] +#![feature(move_trait)] #![feature(panic_internals)] #![feature(pattern)] #![feature(pin_coerce_unsized_trait)] diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 5018ff4ad71f3..7c64ed4f27243 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -251,7 +251,7 @@ use core::hash::{Hash, Hasher}; use core::intrinsics::abort; #[cfg(not(no_global_oom_handling))] use core::iter; -use core::marker::{PhantomData, Unsize}; +use core::marker::{PhantomData, Move, Unsize}; use core::mem::{self, ManuallyDrop, align_of_val_raw}; use core::num::NonZeroUsize; use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver}; @@ -2277,6 +2277,9 @@ unsafe impl DerefPure for UniqueRc {} #[unstable(feature = "legacy_receiver_trait", issue = "none")] impl LegacyReceiver for Rc {} +#[unstable(feature = "move_trait", issue = "none")] +unsafe impl Move for Rc {} + #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Rc { /// Drops the `Rc`. diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index b8925f4544f44..aafa4e0c9be90 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -17,7 +17,7 @@ use core::hash::{Hash, Hasher}; use core::intrinsics::abort; #[cfg(not(no_global_oom_handling))] use core::iter; -use core::marker::{PhantomData, Unsize}; +use core::marker::{PhantomData, Unsize, Move}; use core::mem::{self, ManuallyDrop, align_of_val_raw}; use core::num::NonZeroUsize; use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver}; @@ -271,6 +271,8 @@ pub struct Arc< unsafe impl Send for Arc {} #[stable(feature = "rust1", since = "1.0.0")] unsafe impl Sync for Arc {} +#[unstable(feature = "move_trait", issue = "none")] +unsafe impl Move for Arc {} #[stable(feature = "catch_unwind", since = "1.9.0")] impl UnwindSafe for Arc {} diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 9856e9c18ec68..84f0f8a463ef0 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -59,7 +59,7 @@ use core::cmp::Ordering; use core::hash::{Hash, Hasher}; #[cfg(not(no_global_oom_handling))] use core::iter; -use core::marker::PhantomData; +use core::marker::{PhantomData, Move}; use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; use core::ops::{self, Index, IndexMut, Range, RangeBounds}; use core::ptr::{self, NonNull}; @@ -3908,6 +3908,9 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec { } } +#[unstable(feature = "move_trait", issue = "none")] +unsafe impl Move for Vec {} + #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_default", issue = "143894")] impl const Default for Vec { diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 45277a1c82d3a..6bd1c9fd42e04 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -1366,3 +1366,19 @@ pub macro CoercePointee($item:item) { pub trait CoercePointeeValidated { /* compiler built-in */ } + +/// Types that do not require a stable memory address, and so can be freely +/// `move`d. +#[unstable(feature = "move_trait", issue = "none")] +pub unsafe auto trait Move { + // empty. +} +marker_impls! { + #[unstable(feature = "move_trait", issue = "none")] + unsafe Move for + {T: ?Sized} PhantomData, + {T: ?Sized} *const T, + {T: ?Sized} *mut T, + {T: ?Sized} &T, + {T: ?Sized} &mut T, +} diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index edbdd0411457f..05b8d0b7705c6 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -1327,6 +1327,15 @@ where } } +#[unstable(feature = "move_trait", issue = "none")] +unsafe impl core::marker::Move for HashMap +where + K: Eq + Hash, + V: Eq, + S: BuildHasher, +{ +} + #[stable(feature = "rust1", since = "1.0.0")] impl Eq for HashMap where diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 482d57b47f677..8652a82e3e893 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -1046,6 +1046,14 @@ where { } +#[unstable(feature = "move_trait", issue = "none")] +unsafe impl core::marker::Move for HashSet +where + T: Eq + Hash, + S: BuildHasher, +{ +} + #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for HashSet where diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 77301d7228ead..018f57599d152 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -349,6 +349,7 @@ #![feature(lazy_get)] #![feature(maybe_uninit_slice)] #![feature(maybe_uninit_write_slice)] +#![feature(move_trait)] #![feature(panic_can_unwind)] #![feature(panic_internals)] #![feature(pin_coerce_unsized_trait)] From aceeb51707a044a7897bb86eff188f66e155f806 Mon Sep 17 00:00:00 2001 From: Yosh Date: Wed, 30 Jul 2025 13:57:47 +0200 Subject: [PATCH 02/12] fix tidy failures --- library/alloc/src/boxed.rs | 2 +- library/alloc/src/rc.rs | 2 +- library/alloc/src/sync.rs | 2 +- library/alloc/src/vec/mod.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index e05fadc69ddb8..a7e16804b6a2c 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -191,7 +191,7 @@ use core::error::{self, Error}; use core::fmt; use core::future::Future; use core::hash::{Hash, Hasher}; -use core::marker::{Tuple, Move, Unsize}; +use core::marker::{Move, Tuple, Unsize}; use core::mem::{self, SizedTypeProperties}; use core::ops::{ AsyncFn, AsyncFnMut, AsyncFnOnce, CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut, diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 7c64ed4f27243..53d6a96888f3f 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -251,7 +251,7 @@ use core::hash::{Hash, Hasher}; use core::intrinsics::abort; #[cfg(not(no_global_oom_handling))] use core::iter; -use core::marker::{PhantomData, Move, Unsize}; +use core::marker::{Move, PhantomData, Unsize}; use core::mem::{self, ManuallyDrop, align_of_val_raw}; use core::num::NonZeroUsize; use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver}; diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index aafa4e0c9be90..cbb612c812038 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -17,7 +17,7 @@ use core::hash::{Hash, Hasher}; use core::intrinsics::abort; #[cfg(not(no_global_oom_handling))] use core::iter; -use core::marker::{PhantomData, Unsize, Move}; +use core::marker::{Move, PhantomData, Unsize}; use core::mem::{self, ManuallyDrop, align_of_val_raw}; use core::num::NonZeroUsize; use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver}; diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 84f0f8a463ef0..433c97a32d311 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -59,7 +59,7 @@ use core::cmp::Ordering; use core::hash::{Hash, Hasher}; #[cfg(not(no_global_oom_handling))] use core::iter; -use core::marker::{PhantomData, Move}; +use core::marker::{Move, PhantomData}; use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; use core::ops::{self, Index, IndexMut, Range, RangeBounds}; use core::ptr::{self, NonNull}; From 58614b7cbd27ca4fda9b5326d0087a8856fbb58e Mon Sep 17 00:00:00 2001 From: Yosh Date: Wed, 30 Jul 2025 14:18:14 +0200 Subject: [PATCH 03/12] enable default bounds to check `Move` --- compiler/rustc_session/src/options.rs | 2 +- library/core/src/marker.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 44b35e8921ec3..88078ec1a1c7e 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2241,7 +2241,7 @@ options! { "Use WebAssembly error handling for wasm32-unknown-emscripten"), enforce_type_length_limit: bool = (false, parse_bool, [TRACKED], "enforce the type length limit when monomorphizing instances in codegen"), - experimental_default_bounds: bool = (false, parse_bool, [TRACKED], + experimental_default_bounds: bool = (true, parse_bool, [TRACKED], "enable default bounds for experimental group of auto traits"), export_executable_symbols: bool = (false, parse_bool, [TRACKED], "export symbols from executables, as if they were dynamic libraries"), diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 6bd1c9fd42e04..1944a0d0ebf95 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -1369,6 +1369,7 @@ pub trait CoercePointeeValidated { /// Types that do not require a stable memory address, and so can be freely /// `move`d. +#[lang = "default_trait1"] #[unstable(feature = "move_trait", issue = "none")] pub unsafe auto trait Move { // empty. From 7dfabd6161e37abc84de5b8efab25da912485fd7 Mon Sep 17 00:00:00 2001 From: Yosh Date: Wed, 30 Jul 2025 14:21:53 +0200 Subject: [PATCH 04/12] fix broken tests --- library/alloctests/tests/lib.rs | 1 + library/coretests/tests/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/library/alloctests/tests/lib.rs b/library/alloctests/tests/lib.rs index fcfc7f8dd296d..2d55dfb46674f 100644 --- a/library/alloctests/tests/lib.rs +++ b/library/alloctests/tests/lib.rs @@ -12,6 +12,7 @@ #![feature(int_format_into)] #![feature(linked_list_cursors)] #![feature(map_try_insert)] +#![feature(move_trait)] #![feature(pattern)] #![feature(trusted_len)] #![feature(try_reserve_kind)] diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs index 029a7b00ad36e..160388fbf6c0d 100644 --- a/library/coretests/tests/lib.rs +++ b/library/coretests/tests/lib.rs @@ -74,6 +74,7 @@ #![feature(maybe_uninit_uninit_array_transpose)] #![feature(maybe_uninit_write_slice)] #![feature(min_specialization)] +#![feature(move_trait)] #![feature(never_type)] #![feature(next_index)] #![feature(non_exhaustive_omitted_patterns_lint)] From 844cc5270d2459cfd9497fa303a26fa6baeb3076 Mon Sep 17 00:00:00 2001 From: Yosh Date: Wed, 30 Jul 2025 14:47:16 +0200 Subject: [PATCH 05/12] no more special boys --- library/core/src/marker.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 1944a0d0ebf95..e8c54f89633d1 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -1370,6 +1370,7 @@ pub trait CoercePointeeValidated { /// Types that do not require a stable memory address, and so can be freely /// `move`d. #[lang = "default_trait1"] +#[rustc_unsafe_specialization_marker] #[unstable(feature = "move_trait", issue = "none")] pub unsafe auto trait Move { // empty. From 91f38b3bcb513a4108fad2dc6c470fdb67cf5400 Mon Sep 17 00:00:00 2001 From: Yosh Date: Wed, 30 Jul 2025 17:37:55 +0200 Subject: [PATCH 06/12] relax default `Move` bounds on `DispatchFromDyn` --- library/core/src/ops/unsize.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/ops/unsize.rs b/library/core/src/ops/unsize.rs index f0781ee01fd53..b29f961836484 100644 --- a/library/core/src/ops/unsize.rs +++ b/library/core/src/ops/unsize.rs @@ -116,7 +116,7 @@ impl, U: PointeeSized> CoerceUnsized<*const U> for * /// [^1]: Formerly known as *object safety*. #[unstable(feature = "dispatch_from_dyn", issue = "none")] #[lang = "dispatch_from_dyn"] -pub trait DispatchFromDyn { +pub trait DispatchFromDyn { // Empty. } From 0a4fc48037e83861273eb3f1c8a0424bd529c7ee Mon Sep 17 00:00:00 2001 From: Yosh Date: Wed, 30 Jul 2025 17:49:31 +0200 Subject: [PATCH 07/12] fix path --- library/core/src/ops/unsize.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/ops/unsize.rs b/library/core/src/ops/unsize.rs index b29f961836484..836e38fe646d1 100644 --- a/library/core/src/ops/unsize.rs +++ b/library/core/src/ops/unsize.rs @@ -116,7 +116,7 @@ impl, U: PointeeSized> CoerceUnsized<*const U> for * /// [^1]: Formerly known as *object safety*. #[unstable(feature = "dispatch_from_dyn", issue = "none")] #[lang = "dispatch_from_dyn"] -pub trait DispatchFromDyn { +pub trait DispatchFromDyn { // Empty. } From 35657c02de189bb1008e2b81f766e5d56f5fd0c6 Mon Sep 17 00:00:00 2001 From: Yosh Date: Wed, 30 Jul 2025 20:56:36 +0200 Subject: [PATCH 08/12] relax `Move` bounds on `Unsized` --- library/core/src/marker.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index e8c54f89633d1..884d45e06c7b0 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -237,7 +237,7 @@ pub trait PointeeSized { #[lang = "unsize"] #[rustc_deny_explicit_impl] #[rustc_do_not_implement_via_object] -pub trait Unsize: PointeeSized { +pub trait Unsize: PointeeSized { // Empty. } From ebade90d7ac90dfd36b19620cd9c8ed7f4b7740a Mon Sep 17 00:00:00 2001 From: Yosh Date: Thu, 31 Jul 2025 23:36:58 +0200 Subject: [PATCH 09/12] loosen the bounds on `PointeeSized` impls --- library/core/src/ops/unsize.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/library/core/src/ops/unsize.rs b/library/core/src/ops/unsize.rs index 836e38fe646d1..0499ad43f539d 100644 --- a/library/core/src/ops/unsize.rs +++ b/library/core/src/ops/unsize.rs @@ -39,34 +39,34 @@ pub trait CoerceUnsized { // &mut T -> &mut U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl<'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<&'a mut U> for &'a mut T {} +impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> CoerceUnsized<&'a mut U> for &'a mut T {} // &mut T -> &U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl<'a, 'b: 'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<&'a U> for &'b mut T {} +impl<'a, 'b: 'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> CoerceUnsized<&'a U> for &'b mut T {} // &mut T -> *mut U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl<'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<*mut U> for &'a mut T {} +impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> CoerceUnsized<*mut U> for &'a mut T {} // &mut T -> *const U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl<'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<*const U> for &'a mut T {} +impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> CoerceUnsized<*const U> for &'a mut T {} // &T -> &U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl<'a, 'b: 'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {} +impl<'a, 'b: 'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {} // &T -> *const U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl<'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<*const U> for &'a T {} +impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> CoerceUnsized<*const U> for &'a T {} // *mut T -> *mut U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {} +impl, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {} // *mut T -> *const U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl, U: PointeeSized> CoerceUnsized<*const U> for *mut T {} +impl, U: PointeeSized> CoerceUnsized<*const U> for *mut T {} // *const T -> *const U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl, U: PointeeSized> CoerceUnsized<*const U> for *const T {} +impl, U: PointeeSized> CoerceUnsized<*const U> for *const T {} /// `DispatchFromDyn` is used in the implementation of dyn-compatibility[^1] checks (specifically /// allowing arbitrary self types), to guarantee that a method's receiver type can be dispatched on. @@ -122,13 +122,13 @@ pub trait DispatchFromDyn { // &T -> &U #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl<'a, T: PointeeSized + Unsize, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {} +impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {} // &mut T -> &mut U #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl<'a, T: PointeeSized + Unsize, U: PointeeSized> DispatchFromDyn<&'a mut U> for &'a mut T {} +impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> DispatchFromDyn<&'a mut U> for &'a mut T {} // *const T -> *const U #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl, U: PointeeSized> DispatchFromDyn<*const U> for *const T {} +impl, U: PointeeSized> DispatchFromDyn<*const U> for *const T {} // *mut T -> *mut U #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {} +impl, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {} From 4ed05c2f8b5fa5d54d8f65feb9c02b6ea651aa3c Mon Sep 17 00:00:00 2001 From: Yosh Date: Fri, 1 Aug 2025 03:01:35 +0200 Subject: [PATCH 10/12] The bounds will continue until morale improves --- library/alloc/src/boxed.rs | 2 +- library/core/src/cell.rs | 16 ++++++++-------- library/core/src/marker.rs | 7 +++---- library/core/src/ops/unsize.rs | 8 ++++---- library/core/src/panic/unwind_safe.rs | 2 +- library/core/src/pin.rs | 4 ++-- library/core/src/pin/unsafe_pinned.rs | 6 +++--- library/core/src/ptr/non_null.rs | 8 ++++---- library/core/src/ptr/unique.rs | 4 ++-- 9 files changed, 28 insertions(+), 29 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index a7e16804b6a2c..cf829dc4e2a32 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -2025,7 +2025,7 @@ unsafe impl PinCoerceUnsized for Box {} // Handling arbitrary custom allocators (which can affect the `Box` layout heavily!) // would need a lot of codegen and interpreter adjustments. #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl, U: ?Sized> DispatchFromDyn> for Box {} +impl, U: ?Sized + ?core::marker::Sized> DispatchFromDyn> for Box {} #[stable(feature = "box_borrow", since = "1.1.0")] impl Borrow for Box { diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index d6d1bf2effae2..f74bcf299a01f 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -309,7 +309,7 @@ pub use once::OnceCell; #[stable(feature = "rust1", since = "1.0.0")] #[repr(transparent)] #[rustc_pub_transparent] -pub struct Cell { +pub struct Cell { value: UnsafeCell, } @@ -322,7 +322,7 @@ unsafe impl Send for Cell where T: Send {} // having an explicit negative impl is nice for documentation purposes // and results in nicer error messages. #[stable(feature = "rust1", since = "1.0.0")] -impl !Sync for Cell {} +impl !Sync for Cell {} #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Cell { @@ -668,7 +668,7 @@ impl, U> CoerceUnsized> for Cell {} // `self: Cell<&Self>` won't work // `self: CellWrapper` becomes possible #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl, U> DispatchFromDyn> for Cell {} +impl, U: ?crate::marker::Move> DispatchFromDyn> for Cell {} impl Cell<[T]> { /// Returns a `&[Cell]` from a `&Cell<[T]>` @@ -2090,12 +2090,12 @@ impl fmt::Display for RefMut<'_, T> { #[stable(feature = "rust1", since = "1.0.0")] #[repr(transparent)] #[rustc_pub_transparent] -pub struct UnsafeCell { +pub struct UnsafeCell { value: T, } #[stable(feature = "rust1", since = "1.0.0")] -impl !Sync for UnsafeCell {} +impl !Sync for UnsafeCell {} impl UnsafeCell { /// Constructs a new instance of `UnsafeCell` which will wrap the specified @@ -2359,7 +2359,7 @@ impl, U> CoerceUnsized> for UnsafeCell {} // `self: UnsafeCell<&Self>` won't work // `self: UnsafeCellWrapper` becomes possible #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl, U> DispatchFromDyn> for UnsafeCell {} +impl, U: ?crate::marker::Move> DispatchFromDyn> for UnsafeCell {} /// [`UnsafeCell`], but [`Sync`]. /// @@ -2377,7 +2377,7 @@ impl, U> DispatchFromDyn> for UnsafeCell #[repr(transparent)] #[rustc_diagnostic_item = "SyncUnsafeCell"] #[rustc_pub_transparent] -pub struct SyncUnsafeCell { +pub struct SyncUnsafeCell { value: UnsafeCell, } @@ -2466,7 +2466,7 @@ impl, U> CoerceUnsized> for SyncUnsafeCell // `self: SyncUnsafeCellWrapper` becomes possible #[unstable(feature = "dispatch_from_dyn", issue = "none")] //#[unstable(feature = "sync_unsafe_cell", issue = "95439")] -impl, U> DispatchFromDyn> for SyncUnsafeCell {} +impl, U: ?crate::marker::Move> DispatchFromDyn> for SyncUnsafeCell {} #[allow(unused)] fn assert_coerce_unsized( diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 884d45e06c7b0..1fb397d6066b2 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -820,7 +820,7 @@ impl !Sync for *mut T {} /// [drop check]: Drop#drop-check #[lang = "phantom_data"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct PhantomData; +pub struct PhantomData; #[stable(feature = "rust1", since = "1.0.0")] impl Hash for PhantomData { @@ -914,7 +914,7 @@ pub trait DiscriminantKind { pub unsafe auto trait Freeze {} #[unstable(feature = "freeze", issue = "121675")] -impl !Freeze for UnsafeCell {} +impl !Freeze for UnsafeCell {} marker_impls! { #[unstable(feature = "freeze", issue = "121675")] unsafe Freeze for @@ -934,7 +934,7 @@ marker_impls! { #[lang = "unsafe_unpin"] pub(crate) unsafe auto trait UnsafeUnpin {} -impl !UnsafeUnpin for UnsafePinned {} +impl !UnsafeUnpin for UnsafePinned {} unsafe impl UnsafeUnpin for PhantomData {} unsafe impl UnsafeUnpin for *const T {} unsafe impl UnsafeUnpin for *mut T {} @@ -1378,7 +1378,6 @@ pub unsafe auto trait Move { marker_impls! { #[unstable(feature = "move_trait", issue = "none")] unsafe Move for - {T: ?Sized} PhantomData, {T: ?Sized} *const T, {T: ?Sized} *mut T, {T: ?Sized} &T, diff --git a/library/core/src/ops/unsize.rs b/library/core/src/ops/unsize.rs index 0499ad43f539d..6c2d8f3505d5e 100644 --- a/library/core/src/ops/unsize.rs +++ b/library/core/src/ops/unsize.rs @@ -122,13 +122,13 @@ pub trait DispatchFromDyn { // &T -> &U #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {} +impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized + ?crate::marker::Move> DispatchFromDyn<&'a U> for &'a T {} // &mut T -> &mut U #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> DispatchFromDyn<&'a mut U> for &'a mut T {} +impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized + ?crate::marker::Move> DispatchFromDyn<&'a mut U> for &'a mut T {} // *const T -> *const U #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl, U: PointeeSized> DispatchFromDyn<*const U> for *const T {} +impl, U: PointeeSized + ?crate::marker::Move> DispatchFromDyn<*const U> for *const T {} // *mut T -> *mut U #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {} +impl, U: PointeeSized + ?crate::marker::Move> DispatchFromDyn<*mut U> for *mut T {} diff --git a/library/core/src/panic/unwind_safe.rs b/library/core/src/panic/unwind_safe.rs index a60f0799c0eae..aaa67119bd425 100644 --- a/library/core/src/panic/unwind_safe.rs +++ b/library/core/src/panic/unwind_safe.rs @@ -197,7 +197,7 @@ impl UnwindSafe for AssertUnwindSafe {} // only thing which doesn't implement it (which then transitively applies to // everything else). #[stable(feature = "catch_unwind", since = "1.9.0")] -impl !RefUnwindSafe for UnsafeCell {} +impl !RefUnwindSafe for UnsafeCell {} #[stable(feature = "catch_unwind", since = "1.9.0")] impl RefUnwindSafe for AssertUnwindSafe {} diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs index 14bf7ba90150e..e30021208f131 100644 --- a/library/core/src/pin.rs +++ b/library/core/src/pin.rs @@ -1091,7 +1091,7 @@ pub use self::unsafe_pinned::UnsafePinned; #[repr(transparent)] #[rustc_pub_transparent] #[derive(Copy, Clone)] -pub struct Pin { +pub struct Pin { pointer: Ptr, } @@ -1727,7 +1727,7 @@ where impl DispatchFromDyn> for Pin where Ptr: DispatchFromDyn + PinCoerceUnsized, - U: PinCoerceUnsized, + U: PinCoerceUnsized + ?crate::marker::Move, { } diff --git a/library/core/src/pin/unsafe_pinned.rs b/library/core/src/pin/unsafe_pinned.rs index b18b5d7c9ec0d..70cab05dddd38 100644 --- a/library/core/src/pin/unsafe_pinned.rs +++ b/library/core/src/pin/unsafe_pinned.rs @@ -24,7 +24,7 @@ use crate::{fmt, ptr}; #[lang = "unsafe_pinned"] #[repr(transparent)] #[unstable(feature = "unsafe_pinned", issue = "125735")] -pub struct UnsafePinned { +pub struct UnsafePinned { value: UnsafeCell, } @@ -36,7 +36,7 @@ unsafe impl Sync for UnsafePinned {} /// aliases from becoming invalidated. Therefore let's mark this as `!Unpin`. You can always opt /// back in to `Unpin` with an `impl` block, provided your API is still sound while unpinned. #[unstable(feature = "unsafe_pinned", issue = "125735")] -impl !Unpin for UnsafePinned {} +impl !Unpin for UnsafePinned {} // `Send` and `Sync` are inherited from `T`. This is similar to `SyncUnsafeCell`, since // we eventually concluded that `UnsafeCell` implicitly making things `!Sync` is sometimes @@ -176,6 +176,6 @@ impl, U> CoerceUnsized> for UnsafePinned // FIXME(unsafe_pinned) this logic is copied from UnsafeCell, is it still sound? #[unstable(feature = "dispatch_from_dyn", issue = "none")] // #[unstable(feature = "unsafe_pinned", issue = "125735")] -impl, U> DispatchFromDyn> for UnsafePinned {} +impl, U: ?crate::marker::Move> DispatchFromDyn> for UnsafePinned {} // FIXME(unsafe_pinned): impl PinCoerceUnsized for UnsafePinned? diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 62da6567cca75..7612f27003812 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -72,7 +72,7 @@ use crate::{fmt, hash, intrinsics, mem, ptr}; #[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] #[rustc_diagnostic_item = "NonNull"] -pub struct NonNull { +pub struct NonNull { // Remember to use `.as_ptr()` instead of `.pointer`, as field projecting to // this is banned by . pointer: *const T, @@ -81,12 +81,12 @@ pub struct NonNull { /// `NonNull` pointers are not `Send` because the data they reference may be aliased. // N.B., this impl is unnecessary, but should provide better error messages. #[stable(feature = "nonnull", since = "1.25.0")] -impl !Send for NonNull {} +impl !Send for NonNull {} /// `NonNull` pointers are not `Sync` because the data they reference may be aliased. // N.B., this impl is unnecessary, but should provide better error messages. #[stable(feature = "nonnull", since = "1.25.0")] -impl !Sync for NonNull {} +impl !Sync for NonNull {} impl NonNull { /// Creates a pointer with the given address and no [provenance][crate::ptr#provenance]. @@ -1624,7 +1624,7 @@ impl Copy for NonNull {} impl CoerceUnsized> for NonNull where T: Unsize {} #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl DispatchFromDyn> for NonNull where T: Unsize {} +impl DispatchFromDyn> for NonNull where T: Unsize {} #[stable(feature = "pin", since = "1.33.0")] unsafe impl PinCoerceUnsized for NonNull {} diff --git a/library/core/src/ptr/unique.rs b/library/core/src/ptr/unique.rs index e9e13f9e97f84..b09c055c9eba4 100644 --- a/library/core/src/ptr/unique.rs +++ b/library/core/src/ptr/unique.rs @@ -32,7 +32,7 @@ use crate::ptr::NonNull; )] #[doc(hidden)] #[repr(transparent)] -pub struct Unique { +pub struct Unique { pointer: NonNull, // NOTE: this marker has no consequences for variance, but is necessary // for dropck to understand that we logically own a `T`. @@ -169,7 +169,7 @@ impl Copy for Unique {} impl CoerceUnsized> for Unique where T: Unsize {} #[unstable(feature = "ptr_internals", issue = "none")] -impl DispatchFromDyn> for Unique where T: Unsize {} +impl DispatchFromDyn> for Unique where T: Unsize {} #[unstable(feature = "pin_coerce_unsized_trait", issue = "123430")] unsafe impl PinCoerceUnsized for Unique {} From 01c76d6952cf21b83c95a2a0ea5f86b01b40c8fa Mon Sep 17 00:00:00 2001 From: Yosh Date: Fri, 1 Aug 2025 03:15:54 +0200 Subject: [PATCH 11/12] fix formatting --- library/alloc/src/boxed.rs | 5 ++- library/core/src/cell.rs | 20 +++++----- library/core/src/ops/unsize.rs | 54 +++++++++++++++++++-------- library/core/src/pin/unsafe_pinned.rs | 8 ++-- library/core/src/ptr/non_null.rs | 7 +++- library/core/src/ptr/unique.rs | 9 +++-- 6 files changed, 70 insertions(+), 33 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index cf829dc4e2a32..a3c4e538b1952 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -2025,7 +2025,10 @@ unsafe impl PinCoerceUnsized for Box {} // Handling arbitrary custom allocators (which can affect the `Box` layout heavily!) // would need a lot of codegen and interpreter adjustments. #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl, U: ?Sized + ?core::marker::Sized> DispatchFromDyn> for Box {} +impl, U: ?Sized + ?core::marker::Sized> DispatchFromDyn> + for Box +{ +} #[stable(feature = "box_borrow", since = "1.1.0")] impl Borrow for Box { diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index f74bcf299a01f..5e38a8b788ad0 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -250,9 +250,11 @@ #![stable(feature = "rust1", since = "1.0.0")] +use core::marker::Move; + use crate::cmp::Ordering; use crate::fmt::{self, Debug, Display}; -use crate::marker::{PhantomData, Unsize}; +use crate::marker::{Move, PhantomData, Unsize}; use crate::mem; use crate::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn}; use crate::panic::const_panic; @@ -309,7 +311,7 @@ pub use once::OnceCell; #[stable(feature = "rust1", since = "1.0.0")] #[repr(transparent)] #[rustc_pub_transparent] -pub struct Cell { +pub struct Cell { value: UnsafeCell, } @@ -322,7 +324,7 @@ unsafe impl Send for Cell where T: Send {} // having an explicit negative impl is nice for documentation purposes // and results in nicer error messages. #[stable(feature = "rust1", since = "1.0.0")] -impl !Sync for Cell {} +impl !Sync for Cell {} #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Cell { @@ -668,7 +670,7 @@ impl, U> CoerceUnsized> for Cell {} // `self: Cell<&Self>` won't work // `self: CellWrapper` becomes possible #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl, U: ?crate::marker::Move> DispatchFromDyn> for Cell {} +impl, U: ?Move> DispatchFromDyn> for Cell {} impl Cell<[T]> { /// Returns a `&[Cell]` from a `&Cell<[T]>` @@ -2090,12 +2092,12 @@ impl fmt::Display for RefMut<'_, T> { #[stable(feature = "rust1", since = "1.0.0")] #[repr(transparent)] #[rustc_pub_transparent] -pub struct UnsafeCell { +pub struct UnsafeCell { value: T, } #[stable(feature = "rust1", since = "1.0.0")] -impl !Sync for UnsafeCell {} +impl !Sync for UnsafeCell {} impl UnsafeCell { /// Constructs a new instance of `UnsafeCell` which will wrap the specified @@ -2359,7 +2361,7 @@ impl, U> CoerceUnsized> for UnsafeCell {} // `self: UnsafeCell<&Self>` won't work // `self: UnsafeCellWrapper` becomes possible #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl, U: ?crate::marker::Move> DispatchFromDyn> for UnsafeCell {} +impl, U: ?Move> DispatchFromDyn> for UnsafeCell {} /// [`UnsafeCell`], but [`Sync`]. /// @@ -2377,7 +2379,7 @@ impl, U: ?crate::marker::Move> DispatchFromDyn { +pub struct SyncUnsafeCell { value: UnsafeCell, } @@ -2466,7 +2468,7 @@ impl, U> CoerceUnsized> for SyncUnsafeCell // `self: SyncUnsafeCellWrapper` becomes possible #[unstable(feature = "dispatch_from_dyn", issue = "none")] //#[unstable(feature = "sync_unsafe_cell", issue = "95439")] -impl, U: ?crate::marker::Move> DispatchFromDyn> for SyncUnsafeCell {} +impl, U: ?Move> DispatchFromDyn> for SyncUnsafeCell {} #[allow(unused)] fn assert_coerce_unsized( diff --git a/library/core/src/ops/unsize.rs b/library/core/src/ops/unsize.rs index 6c2d8f3505d5e..6ba0bd7fdd320 100644 --- a/library/core/src/ops/unsize.rs +++ b/library/core/src/ops/unsize.rs @@ -1,4 +1,4 @@ -use crate::marker::{PointeeSized, Unsize}; +use crate::marker::{Move, PointeeSized, Unsize}; /// Trait that indicates that this is a pointer or a wrapper for one, /// where unsizing can be performed on the pointee. @@ -39,34 +39,46 @@ pub trait CoerceUnsized { // &mut T -> &mut U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> CoerceUnsized<&'a mut U> for &'a mut T {} +impl<'a, T: PointeeSized + ?Move + Unsize, U: PointeeSized> CoerceUnsized<&'a mut U> + for &'a mut T +{ +} // &mut T -> &U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl<'a, 'b: 'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> CoerceUnsized<&'a U> for &'b mut T {} +impl<'a, 'b: 'a, T: PointeeSized + ?Move + Unsize, U: PointeeSized> CoerceUnsized<&'a U> + for &'b mut T +{ +} // &mut T -> *mut U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> CoerceUnsized<*mut U> for &'a mut T {} +impl<'a, T: PointeeSized + ?Move + Unsize, U: PointeeSized> CoerceUnsized<*mut U> for &'a mut T {} // &mut T -> *const U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> CoerceUnsized<*const U> for &'a mut T {} +impl<'a, T: PointeeSized + ?Move + Unsize, U: PointeeSized> CoerceUnsized<*const U> + for &'a mut T +{ +} // &T -> &U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl<'a, 'b: 'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {} +impl<'a, 'b: 'a, T: PointeeSized + ?Move + Unsize, U: PointeeSized> CoerceUnsized<&'a U> + for &'b T +{ +} // &T -> *const U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized> CoerceUnsized<*const U> for &'a T {} +impl<'a, T: PointeeSized + ?Move + Unsize, U: PointeeSized> CoerceUnsized<*const U> for &'a T {} // *mut T -> *mut U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {} +impl, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {} // *mut T -> *const U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl, U: PointeeSized> CoerceUnsized<*const U> for *mut T {} +impl, U: PointeeSized> CoerceUnsized<*const U> for *mut T {} // *const T -> *const U #[unstable(feature = "coerce_unsized", issue = "18598")] -impl, U: PointeeSized> CoerceUnsized<*const U> for *const T {} +impl, U: PointeeSized> CoerceUnsized<*const U> for *const T {} /// `DispatchFromDyn` is used in the implementation of dyn-compatibility[^1] checks (specifically /// allowing arbitrary self types), to guarantee that a method's receiver type can be dispatched on. @@ -116,19 +128,31 @@ impl, U: PointeeSized> Coerce /// [^1]: Formerly known as *object safety*. #[unstable(feature = "dispatch_from_dyn", issue = "none")] #[lang = "dispatch_from_dyn"] -pub trait DispatchFromDyn { +pub trait DispatchFromDyn { // Empty. } // &T -> &U #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized + ?crate::marker::Move> DispatchFromDyn<&'a U> for &'a T {} +impl<'a, T: PointeeSized + ?Move + Unsize, U: PointeeSized + ?Move> DispatchFromDyn<&'a U> + for &'a T +{ +} // &mut T -> &mut U #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl<'a, T: PointeeSized + ?crate::marker::Move + Unsize, U: PointeeSized + ?crate::marker::Move> DispatchFromDyn<&'a mut U> for &'a mut T {} +impl<'a, T: PointeeSized + ?Move + Unsize, U: PointeeSized + ?Move> DispatchFromDyn<&'a mut U> + for &'a mut T +{ +} // *const T -> *const U #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl, U: PointeeSized + ?crate::marker::Move> DispatchFromDyn<*const U> for *const T {} +impl, U: PointeeSized + ?Move> DispatchFromDyn<*const U> + for *const T +{ +} // *mut T -> *mut U #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl, U: PointeeSized + ?crate::marker::Move> DispatchFromDyn<*mut U> for *mut T {} +impl, U: PointeeSized + ?Move> DispatchFromDyn<*mut U> + for *mut T +{ +} diff --git a/library/core/src/pin/unsafe_pinned.rs b/library/core/src/pin/unsafe_pinned.rs index 70cab05dddd38..4036312cfbffc 100644 --- a/library/core/src/pin/unsafe_pinned.rs +++ b/library/core/src/pin/unsafe_pinned.rs @@ -1,5 +1,5 @@ use crate::cell::UnsafeCell; -use crate::marker::Unpin; +use crate::marker::{Move, Unpin}; use crate::ops::{CoerceUnsized, DispatchFromDyn}; use crate::pin::Pin; use crate::{fmt, ptr}; @@ -24,7 +24,7 @@ use crate::{fmt, ptr}; #[lang = "unsafe_pinned"] #[repr(transparent)] #[unstable(feature = "unsafe_pinned", issue = "125735")] -pub struct UnsafePinned { +pub struct UnsafePinned { value: UnsafeCell, } @@ -36,7 +36,7 @@ unsafe impl Sync for UnsafePinned {} /// aliases from becoming invalidated. Therefore let's mark this as `!Unpin`. You can always opt /// back in to `Unpin` with an `impl` block, provided your API is still sound while unpinned. #[unstable(feature = "unsafe_pinned", issue = "125735")] -impl !Unpin for UnsafePinned {} +impl !Unpin for UnsafePinned {} // `Send` and `Sync` are inherited from `T`. This is similar to `SyncUnsafeCell`, since // we eventually concluded that `UnsafeCell` implicitly making things `!Sync` is sometimes @@ -176,6 +176,6 @@ impl, U> CoerceUnsized> for UnsafePinned // FIXME(unsafe_pinned) this logic is copied from UnsafeCell, is it still sound? #[unstable(feature = "dispatch_from_dyn", issue = "none")] // #[unstable(feature = "unsafe_pinned", issue = "125735")] -impl, U: ?crate::marker::Move> DispatchFromDyn> for UnsafePinned {} +impl, U: ?Move> DispatchFromDyn> for UnsafePinned {} // FIXME(unsafe_pinned): impl PinCoerceUnsized for UnsafePinned? diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 7612f27003812..2b20268973e98 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1,3 +1,5 @@ +use core::marker::Move; + use crate::cmp::Ordering; use crate::marker::{PointeeSized, Unsize}; use crate::mem::{MaybeUninit, SizedTypeProperties}; @@ -1624,7 +1626,10 @@ impl Copy for NonNull {} impl CoerceUnsized> for NonNull where T: Unsize {} #[unstable(feature = "dispatch_from_dyn", issue = "none")] -impl DispatchFromDyn> for NonNull where T: Unsize {} +impl DispatchFromDyn> for NonNull where + T: Unsize +{ +} #[stable(feature = "pin", since = "1.33.0")] unsafe impl PinCoerceUnsized for NonNull {} diff --git a/library/core/src/ptr/unique.rs b/library/core/src/ptr/unique.rs index b09c055c9eba4..9db2b49be9335 100644 --- a/library/core/src/ptr/unique.rs +++ b/library/core/src/ptr/unique.rs @@ -1,5 +1,5 @@ use crate::fmt; -use crate::marker::{PhantomData, PointeeSized, Unsize}; +use crate::marker::{Move, PhantomData, PointeeSized, Unsize}; use crate::ops::{CoerceUnsized, DispatchFromDyn}; use crate::pin::PinCoerceUnsized; use crate::ptr::NonNull; @@ -32,7 +32,7 @@ use crate::ptr::NonNull; )] #[doc(hidden)] #[repr(transparent)] -pub struct Unique { +pub struct Unique { pointer: NonNull, // NOTE: this marker has no consequences for variance, but is necessary // for dropck to understand that we logically own a `T`. @@ -169,7 +169,10 @@ impl Copy for Unique {} impl CoerceUnsized> for Unique where T: Unsize {} #[unstable(feature = "ptr_internals", issue = "none")] -impl DispatchFromDyn> for Unique where T: Unsize {} +impl DispatchFromDyn> for Unique where + T: Unsize +{ +} #[unstable(feature = "pin_coerce_unsized_trait", issue = "123430")] unsafe impl PinCoerceUnsized for Unique {} From f859430ad081e4cdb9a845266fa6367d497ba6f3 Mon Sep 17 00:00:00 2001 From: Yosh Date: Fri, 1 Aug 2025 03:19:04 +0200 Subject: [PATCH 12/12] fix duplicate Move import --- library/core/src/cell.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index 5e38a8b788ad0..a3914e2fc1ba2 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -250,8 +250,6 @@ #![stable(feature = "rust1", since = "1.0.0")] -use core::marker::Move; - use crate::cmp::Ordering; use crate::fmt::{self, Debug, Display}; use crate::marker::{Move, PhantomData, Unsize};