Skip to content

Commit ce349ac

Browse files
Auto merge of #144679 - yoshuawuyts:move-trait, r=<try>
[do not merge] Add a `Move` marker trait
2 parents e5e79f8 + 7dfabd6 commit ce349ac

File tree

14 files changed

+60
-5
lines changed

14 files changed

+60
-5
lines changed

compiler/rustc_session/src/options.rs

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

library/alloc/src/boxed.rs

Lines changed: 4 additions & 1 deletion
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,
@@ -2132,3 +2132,6 @@ impl<E: Error> Error for Box<E> {
21322132
Error::provide(&**self, request);
21332133
}
21342134
}
2135+
2136+
#[unstable(feature = "move_trait", issue = "none")]
2137+
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
@@ -190,6 +190,9 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V, A: Allocator + Clone> Drop for BTr
190190
}
191191
}
192192

193+
#[unstable(feature = "move_trait", issue = "none")]
194+
unsafe impl<K, V, A: Allocator + Clone> core::marker::Move for BTreeMap<K, V, A> {}
195+
193196
// FIXME: This implementation is "wrong", but changing it would be a breaking change.
194197
// (The bounds of the automatic `UnwindSafe` implementation have been like this since Rust 1.50.)
195198
// 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
@@ -3025,6 +3025,9 @@ impl<T, A: Allocator> IndexMut<usize> for VecDeque<T, A> {
30253025
}
30263026
}
30273027

3028+
#[unstable(feature = "move_trait", issue = "none")]
3029+
unsafe impl<T, A: Allocator> core::marker::Move for VecDeque<T, A> {}
3030+
30283031
#[stable(feature = "rust1", since = "1.0.0")]
30293032
impl<T> FromIterator<T> for VecDeque<T> {
30303033
#[track_caller]

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
#![feature(local_waker)]
133133
#![feature(maybe_uninit_slice)]
134134
#![feature(maybe_uninit_uninit_array_transpose)]
135+
#![feature(move_trait)]
135136
#![feature(panic_internals)]
136137
#![feature(pattern)]
137138
#![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
@@ -59,7 +59,7 @@ use core::cmp::Ordering;
5959
use core::hash::{Hash, Hasher};
6060
#[cfg(not(no_global_oom_handling))]
6161
use core::iter;
62-
use core::marker::PhantomData;
62+
use core::marker::{Move, PhantomData};
6363
use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties};
6464
use core::ops::{self, Index, IndexMut, Range, RangeBounds};
6565
use core::ptr::{self, NonNull};
@@ -3908,6 +3908,9 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> {
39083908
}
39093909
}
39103910

3911+
#[unstable(feature = "move_trait", issue = "none")]
3912+
unsafe impl<T> Move for Vec<T> {}
3913+
39113914
#[stable(feature = "rust1", since = "1.0.0")]
39123915
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
39133916
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
@@ -12,6 +12,7 @@
1212
#![feature(int_format_into)]
1313
#![feature(linked_list_cursors)]
1414
#![feature(map_try_insert)]
15+
#![feature(move_trait)]
1516
#![feature(pattern)]
1617
#![feature(trusted_len)]
1718
#![feature(try_reserve_kind)]

library/core/src/marker.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,3 +1366,20 @@ pub macro CoercePointee($item:item) {
13661366
pub trait CoercePointeeValidated {
13671367
/* compiler built-in */
13681368
}
1369+
1370+
/// Types that do not require a stable memory address, and so can be freely
1371+
/// `move`d.
1372+
#[lang = "default_trait1"]
1373+
#[unstable(feature = "move_trait", issue = "none")]
1374+
pub unsafe auto trait Move {
1375+
// empty.
1376+
}
1377+
marker_impls! {
1378+
#[unstable(feature = "move_trait", issue = "none")]
1379+
unsafe Move for
1380+
{T: ?Sized} PhantomData<T>,
1381+
{T: ?Sized} *const T,
1382+
{T: ?Sized} *mut T,
1383+
{T: ?Sized} &T,
1384+
{T: ?Sized} &mut T,
1385+
}

0 commit comments

Comments
 (0)