Skip to content

Commit a549f68

Browse files
yoshuawuytslcnr
authored andcommitted
Add a Move marker trait
impl Move for more types
1 parent 45b9d13 commit a549f68

File tree

21 files changed

+138
-48
lines changed

21 files changed

+138
-48
lines changed

compiler/rustc_session/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2240,7 +2240,7 @@ options! {
22402240
"Use WebAssembly error handling for wasm32-unknown-emscripten"),
22412241
enforce_type_length_limit: bool = (false, parse_bool, [TRACKED],
22422242
"enforce the type length limit when monomorphizing instances in codegen"),
2243-
experimental_default_bounds: bool = (false, parse_bool, [TRACKED],
2243+
experimental_default_bounds: bool = (true, parse_bool, [TRACKED],
22442244
"enable default bounds for experimental group of auto traits"),
22452245
export_executable_symbols: bool = (false, parse_bool, [TRACKED],
22462246
"export symbols from executables, as if they were dynamic libraries"),

library/alloc/src/boxed.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ use core::error::{self, Error};
191191
use core::fmt;
192192
use core::future::Future;
193193
use core::hash::{Hash, Hasher};
194-
use core::marker::{Tuple, Unsize};
194+
use core::marker::{Move, Tuple, Unsize};
195195
use core::mem::{self, SizedTypeProperties};
196196
use core::ops::{
197197
AsyncFn, AsyncFnMut, AsyncFnOnce, CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut,
@@ -2039,7 +2039,10 @@ unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Box<T, A> {}
20392039
// Handling arbitrary custom allocators (which can affect the `Box` layout heavily!)
20402040
// would need a lot of codegen and interpreter adjustments.
20412041
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
2042-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T, Global> {}
2042+
impl<T: ?Sized + Unsize<U>, U: ?Sized + ?core::marker::Sized> DispatchFromDyn<Box<U>>
2043+
for Box<T, Global>
2044+
{
2045+
}
20432046

20442047
#[stable(feature = "box_borrow", since = "1.1.0")]
20452048
impl<T: ?Sized, A: Allocator> Borrow<T> for Box<T, A> {
@@ -2141,3 +2144,6 @@ impl<E: Error> Error for Box<E> {
21412144
Error::provide(&**self, request);
21422145
}
21432146
}
2147+
2148+
#[unstable(feature = "move_trait", issue = "none")]
2149+
unsafe impl<T: ?Sized> Move for Box<T> {}

library/alloc/src/collections/btree/map.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V, A: Allocator + Clone> Drop for BTr
206206
}
207207
}
208208

209+
#[unstable(feature = "move_trait", issue = "none")]
210+
unsafe impl<K, V, A: Allocator + Clone> core::marker::Move for BTreeMap<K, V, A> {}
211+
209212
// FIXME: This implementation is "wrong", but changing it would be a breaking change.
210213
// (The bounds of the automatic `UnwindSafe` implementation have been like this since Rust 1.50.)
211214
// Maybe we can fix it nonetheless with a crater run, or if the `UnwindSafe`

library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,6 +3099,9 @@ impl<T, A: Allocator> IndexMut<usize> for VecDeque<T, A> {
30993099
}
31003100
}
31013101

3102+
#[unstable(feature = "move_trait", issue = "none")]
3103+
unsafe impl<T, A: Allocator> core::marker::Move for VecDeque<T, A> {}
3104+
31023105
#[stable(feature = "rust1", since = "1.0.0")]
31033106
impl<T> FromIterator<T> for VecDeque<T> {
31043107
#[track_caller]

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
#![feature(local_waker)]
134134
#![feature(maybe_uninit_slice)]
135135
#![feature(maybe_uninit_uninit_array_transpose)]
136+
#![feature(move_trait)]
136137
#![feature(panic_internals)]
137138
#![feature(pattern)]
138139
#![feature(pin_coerce_unsized_trait)]

library/alloc/src/rc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ use core::hash::{Hash, Hasher};
251251
use core::intrinsics::abort;
252252
#[cfg(not(no_global_oom_handling))]
253253
use core::iter;
254-
use core::marker::{PhantomData, Unsize};
254+
use core::marker::{Move, PhantomData, Unsize};
255255
use core::mem::{self, ManuallyDrop, align_of_val_raw};
256256
use core::num::NonZeroUsize;
257257
use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver};
@@ -2277,6 +2277,9 @@ unsafe impl<T: ?Sized, A: Allocator> DerefPure for UniqueRc<T, A> {}
22772277
#[unstable(feature = "legacy_receiver_trait", issue = "none")]
22782278
impl<T: ?Sized> LegacyReceiver for Rc<T> {}
22792279

2280+
#[unstable(feature = "move_trait", issue = "none")]
2281+
unsafe impl<T: ?Sized, A: Allocator> Move for Rc<T, A> {}
2282+
22802283
#[stable(feature = "rust1", since = "1.0.0")]
22812284
unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Rc<T, A> {
22822285
/// Drops the `Rc`.

library/alloc/src/sync.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use core::hash::{Hash, Hasher};
1717
use core::intrinsics::abort;
1818
#[cfg(not(no_global_oom_handling))]
1919
use core::iter;
20-
use core::marker::{PhantomData, Unsize};
20+
use core::marker::{Move, PhantomData, Unsize};
2121
use core::mem::{self, ManuallyDrop, align_of_val_raw};
2222
use core::num::NonZeroUsize;
2323
use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver};
@@ -271,6 +271,8 @@ pub struct Arc<
271271
unsafe impl<T: ?Sized + Sync + Send, A: Allocator + Send> Send for Arc<T, A> {}
272272
#[stable(feature = "rust1", since = "1.0.0")]
273273
unsafe impl<T: ?Sized + Sync + Send, A: Allocator + Sync> Sync for Arc<T, A> {}
274+
#[unstable(feature = "move_trait", issue = "none")]
275+
unsafe impl<T: ?Sized, A: Allocator> Move for Arc<T, A> {}
274276

275277
#[stable(feature = "catch_unwind", since = "1.9.0")]
276278
impl<T: RefUnwindSafe + ?Sized, A: Allocator + UnwindSafe> UnwindSafe for Arc<T, A> {}

library/alloc/src/vec/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ use core::cmp::Ordering;
7979
use core::hash::{Hash, Hasher};
8080
#[cfg(not(no_global_oom_handling))]
8181
use core::iter;
82-
use core::marker::PhantomData;
82+
use core::marker::{Move, PhantomData};
8383
use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties};
8484
use core::ops::{self, Index, IndexMut, Range, RangeBounds};
8585
use core::ptr::{self, NonNull};
@@ -4052,6 +4052,9 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> {
40524052
}
40534053
}
40544054

4055+
#[unstable(feature = "move_trait", issue = "none")]
4056+
unsafe impl<T> Move for Vec<T> {}
4057+
40554058
#[stable(feature = "rust1", since = "1.0.0")]
40564059
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
40574060
impl<T> const Default for Vec<T> {

library/alloctests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(int_format_into)]
1414
#![feature(linked_list_cursors)]
1515
#![feature(map_try_insert)]
16+
#![feature(move_trait)]
1617
#![feature(pattern)]
1718
#![feature(trusted_len)]
1819
#![feature(try_reserve_kind)]

library/core/src/cell.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252

253253
use crate::cmp::Ordering;
254254
use crate::fmt::{self, Debug, Display};
255-
use crate::marker::{PhantomData, Unsize};
255+
use crate::marker::{Move, PhantomData, Unsize};
256256
use crate::mem;
257257
use crate::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn};
258258
use crate::panic::const_panic;
@@ -309,7 +309,7 @@ pub use once::OnceCell;
309309
#[stable(feature = "rust1", since = "1.0.0")]
310310
#[repr(transparent)]
311311
#[rustc_pub_transparent]
312-
pub struct Cell<T: ?Sized> {
312+
pub struct Cell<T: ?Sized + ?Move> {
313313
value: UnsafeCell<T>,
314314
}
315315

@@ -322,7 +322,7 @@ unsafe impl<T: ?Sized> Send for Cell<T> where T: Send {}
322322
// having an explicit negative impl is nice for documentation purposes
323323
// and results in nicer error messages.
324324
#[stable(feature = "rust1", since = "1.0.0")]
325-
impl<T: ?Sized> !Sync for Cell<T> {}
325+
impl<T: ?Sized + ?Move> !Sync for Cell<T> {}
326326

327327
#[stable(feature = "rust1", since = "1.0.0")]
328328
impl<T: Copy> Clone for Cell<T> {
@@ -669,7 +669,7 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {}
669669
// `self: Cell<&Self>` won't work
670670
// `self: CellWrapper<Self>` becomes possible
671671
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
672-
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Cell<U>> for Cell<T> {}
672+
impl<T: DispatchFromDyn<U>, U: ?Move> DispatchFromDyn<Cell<U>> for Cell<T> {}
673673

674674
impl<T> Cell<[T]> {
675675
/// Returns a `&[Cell<T>]` from a `&Cell<[T]>`
@@ -2185,12 +2185,12 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
21852185
#[stable(feature = "rust1", since = "1.0.0")]
21862186
#[repr(transparent)]
21872187
#[rustc_pub_transparent]
2188-
pub struct UnsafeCell<T: ?Sized> {
2188+
pub struct UnsafeCell<T: ?Sized + ?Move> {
21892189
value: T,
21902190
}
21912191

21922192
#[stable(feature = "rust1", since = "1.0.0")]
2193-
impl<T: ?Sized> !Sync for UnsafeCell<T> {}
2193+
impl<T: ?Sized + ?Move> !Sync for UnsafeCell<T> {}
21942194

21952195
impl<T> UnsafeCell<T> {
21962196
/// Constructs a new instance of `UnsafeCell` which will wrap the specified
@@ -2455,7 +2455,7 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
24552455
// `self: UnsafeCell<&Self>` won't work
24562456
// `self: UnsafeCellWrapper<Self>` becomes possible
24572457
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
2458-
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T> {}
2458+
impl<T: DispatchFromDyn<U>, U: ?Move> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T> {}
24592459

24602460
/// [`UnsafeCell`], but [`Sync`].
24612461
///
@@ -2473,7 +2473,7 @@ impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T>
24732473
#[repr(transparent)]
24742474
#[rustc_diagnostic_item = "SyncUnsafeCell"]
24752475
#[rustc_pub_transparent]
2476-
pub struct SyncUnsafeCell<T: ?Sized> {
2476+
pub struct SyncUnsafeCell<T: ?Sized + ?Move> {
24772477
value: UnsafeCell<T>,
24782478
}
24792479

@@ -2563,7 +2563,7 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<SyncUnsafeCell<U>> for SyncUnsafeCell
25632563
// `self: SyncUnsafeCellWrapper<Self>` becomes possible
25642564
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
25652565
//#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2566-
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {}
2566+
impl<T: DispatchFromDyn<U>, U: ?Move> DispatchFromDyn<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {}
25672567

25682568
#[allow(unused)]
25692569
fn assert_coerce_unsized(

0 commit comments

Comments
 (0)