Skip to content

Commit 3c96da1

Browse files
committed
Auto merge of #44917 - Zoxc:move, r=<try>
DO NOT MERGE: Immovable types prototype where the Move trait is builtin
2 parents a379780 + 6d6240e commit 3c96da1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1133
-155
lines changed

src/liballoc/boxed.rs

+16
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ pub trait FnBox<A> {
717717
fn call_box(self: Box<Self>, args: A) -> Self::Output;
718718
}
719719

720+
#[cfg(stage0)]
720721
#[unstable(feature = "fnbox",
721722
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
722723
impl<A, F> FnBox<A> for F
@@ -729,6 +730,21 @@ impl<A, F> FnBox<A> for F
729730
}
730731
}
731732

733+
#[cfg(not(stage0))]
734+
#[unstable(feature = "fnbox",
735+
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
736+
impl<A, F> FnBox<A> for F
737+
where F: FnOnce<A>,
738+
<F as FnOnce<A>>::Output: marker::Move,
739+
740+
{
741+
type Output = F::Output;
742+
743+
fn call_box(self: Box<F>, args: A) -> F::Output {
744+
self.call_once(args)
745+
}
746+
}
747+
732748
#[unstable(feature = "fnbox",
733749
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
734750
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
#![feature(slice_rsplit)]
115115
#![feature(specialization)]
116116
#![feature(staged_api)]
117+
#![cfg_attr(not(stage0), feature(immovable_types))]
117118
#![feature(str_internals)]
118119
#![feature(trusted_len)]
119120
#![feature(unboxed_closures)]

src/libcore/cell.rs

+33
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ use marker::Unsize;
185185
use mem;
186186
use ops::{Deref, DerefMut, CoerceUnsized};
187187
use ptr;
188+
#[cfg(not(stage0))]
189+
use marker::Move;
188190

189191
/// A mutable memory location.
190192
///
@@ -1267,3 +1269,34 @@ fn assert_coerce_unsized(a: UnsafeCell<&i32>, b: Cell<&i32>, c: RefCell<&i32>) {
12671269
let _: Cell<&Send> = b;
12681270
let _: RefCell<&Send> = c;
12691271
}
1272+
1273+
/// A cell that is always movable, even if the interior type is immovable.
1274+
/// This prevents pointers to the inner type which means it can never be observed.
1275+
#[cfg(not(stage0))]
1276+
#[unstable(feature = "immovable_types", issue = "0")]
1277+
#[lang = "movable_cell"]
1278+
#[derive(Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Hash, Debug)]
1279+
pub struct MovableCell<T: ?Move> {
1280+
value: T,
1281+
}
1282+
1283+
#[unstable(feature = "immovable_types", issue = "0")]
1284+
#[cfg(not(stage0))]
1285+
impl<T: ?Move> MovableCell<T> {
1286+
/// Creates a new MovableCell.
1287+
pub const fn new(value: T) -> Self {
1288+
MovableCell {
1289+
value: value,
1290+
}
1291+
}
1292+
1293+
/// Extracts the inner value.
1294+
pub fn into_inner(self) -> T {
1295+
self.value
1296+
}
1297+
1298+
/// Replaces the inner value.
1299+
pub fn replace(&mut self, new_value: T) -> T {
1300+
mem::replace(self, MovableCell::new(new_value)).into_inner()
1301+
}
1302+
}

src/libcore/marker.rs

+76
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,37 @@ use hash::Hasher;
4141
#[stable(feature = "rust1", since = "1.0.0")]
4242
#[lang = "send"]
4343
#[rustc_on_unimplemented = "`{Self}` cannot be sent between threads safely"]
44+
#[cfg(not(stage0))]
45+
pub unsafe trait Send: ?Move {
46+
// empty.
47+
}
48+
49+
/// docs
50+
#[stable(feature = "rust1", since = "1.0.0")]
51+
#[lang = "send"]
52+
#[rustc_on_unimplemented = "`{Self}` cannot be sent between threads safely"]
53+
#[cfg(stage0)]
4454
pub unsafe trait Send {
4555
// empty.
4656
}
4757

4858
#[stable(feature = "rust1", since = "1.0.0")]
4959
unsafe impl Send for .. { }
5060

61+
#[cfg(stage0)]
5162
#[stable(feature = "rust1", since = "1.0.0")]
5263
impl<T: ?Sized> !Send for *const T { }
64+
#[cfg(stage0)]
5365
#[stable(feature = "rust1", since = "1.0.0")]
5466
impl<T: ?Sized> !Send for *mut T { }
5567

68+
#[cfg(not(stage0))]
69+
#[stable(feature = "rust1", since = "1.0.0")]
70+
impl<T: ?Sized+?Move> !Send for *const T { }
71+
#[cfg(not(stage0))]
72+
#[stable(feature = "rust1", since = "1.0.0")]
73+
impl<T: ?Sized+?Move> !Send for *mut T { }
74+
5675
/// Types with a constant size known at compile time.
5776
///
5877
/// All type parameters have an implicit bound of `Sized`. The special syntax
@@ -90,10 +109,36 @@ impl<T: ?Sized> !Send for *mut T { }
90109
#[lang = "sized"]
91110
#[rustc_on_unimplemented = "`{Self}` does not have a constant size known at compile-time"]
92111
#[fundamental] // for Default, for example, which requires that `[T]: !Default` be evaluatable
112+
#[cfg(not(stage0))]
113+
pub trait Sized: ?Move {
114+
// Empty.
115+
}
116+
117+
/// docs
118+
#[stable(feature = "rust1", since = "1.0.0")]
119+
#[lang = "sized"]
120+
#[rustc_on_unimplemented = "`{Self}` does not have a constant size known at compile-time"]
121+
#[fundamental] // for Default, for example, which requires that `[T]: !Default` be evaluatable
122+
#[cfg(stage0)]
93123
pub trait Sized {
94124
// Empty.
95125
}
96126

127+
/// Types that can be moved after being borrowed.
128+
#[cfg(not(stage0))]
129+
#[lang = "move"]
130+
#[unstable(feature = "immovable_types", issue = "0")]
131+
pub unsafe trait Move: ?Move {
132+
// Empty.
133+
}
134+
135+
/// A zero-sized struct which is immovable.
136+
#[cfg(not(stage0))]
137+
#[lang = "immovable"]
138+
#[unstable(feature = "immovable_types", issue = "0")]
139+
#[allow(missing_debug_implementations)]
140+
pub struct Immovable;
141+
97142
/// Types that can be "unsized" to a dynamically-sized type.
98143
///
99144
/// For example, the sized array type `[i8; 2]` implements `Unsize<[i8]>` and
@@ -344,18 +389,37 @@ pub trait Copy : Clone {
344389
#[stable(feature = "rust1", since = "1.0.0")]
345390
#[lang = "sync"]
346391
#[rustc_on_unimplemented = "`{Self}` cannot be shared between threads safely"]
392+
#[cfg(not(stage0))]
393+
pub unsafe trait Sync: ?Move {
394+
// Empty
395+
}
396+
397+
/// docs
398+
#[stable(feature = "rust1", since = "1.0.0")]
399+
#[lang = "sync"]
400+
#[rustc_on_unimplemented = "`{Self}` cannot be shared between threads safely"]
401+
#[cfg(stage0)]
347402
pub unsafe trait Sync {
348403
// Empty
349404
}
350405

351406
#[stable(feature = "rust1", since = "1.0.0")]
352407
unsafe impl Sync for .. { }
353408

409+
#[cfg(stage0)]
354410
#[stable(feature = "rust1", since = "1.0.0")]
355411
impl<T: ?Sized> !Sync for *const T { }
412+
#[cfg(stage0)]
356413
#[stable(feature = "rust1", since = "1.0.0")]
357414
impl<T: ?Sized> !Sync for *mut T { }
358415

416+
#[cfg(not(stage0))]
417+
#[stable(feature = "rust1", since = "1.0.0")]
418+
impl<T: ?Sized+?Move> !Sync for *const T { }
419+
#[cfg(not(stage0))]
420+
#[stable(feature = "rust1", since = "1.0.0")]
421+
impl<T: ?Sized+?Move> !Sync for *mut T { }
422+
359423
macro_rules! impls{
360424
($t: ident) => (
361425
#[stable(feature = "rust1", since = "1.0.0")]
@@ -542,6 +606,13 @@ macro_rules! impls{
542606
/// as not to indicate ownership.
543607
///
544608
/// [drop check]: ../../nomicon/dropck.html
609+
#[cfg(not(stage0))]
610+
#[lang = "phantom_data"]
611+
#[stable(feature = "rust1", since = "1.0.0")]
612+
pub struct PhantomData<T:?Sized+?Move>;
613+
614+
/// docs
615+
#[cfg(stage0)]
545616
#[lang = "phantom_data"]
546617
#[stable(feature = "rust1", since = "1.0.0")]
547618
pub struct PhantomData<T:?Sized>;
@@ -560,6 +631,11 @@ mod impls {
560631
/// This affects, for example, whether a `static` of that type is
561632
/// placed in read-only static memory or writable static memory.
562633
#[lang = "freeze"]
634+
#[cfg(not(stage0))]
635+
unsafe trait Freeze: ?Move {}
636+
637+
#[lang = "freeze"]
638+
#[cfg(stage0)]
563639
unsafe trait Freeze {}
564640

565641
unsafe impl Freeze for .. {}

src/libcore/nonzero.rs

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
issue = "27730")]
1515

1616
use ops::CoerceUnsized;
17+
#[cfg(not(stage0))]
18+
use marker::Move;
1719

1820
/// Unsafe trait to indicate what types are usable with the NonZero struct
1921
pub unsafe trait Zeroable {
@@ -24,6 +26,7 @@ pub unsafe trait Zeroable {
2426
macro_rules! impl_zeroable_for_pointer_types {
2527
( $( $Ptr: ty )+ ) => {
2628
$(
29+
#[cfg(stage0)]
2730
/// For fat pointers to be considered "zero", only the "data" part needs to be null.
2831
unsafe impl<T: ?Sized> Zeroable for $Ptr {
2932
#[inline]
@@ -32,6 +35,15 @@ macro_rules! impl_zeroable_for_pointer_types {
3235
(*self as *mut u8).is_null()
3336
}
3437
}
38+
#[cfg(not(stage0))]
39+
/// For fat pointers to be considered "zero", only the "data" part needs to be null.
40+
unsafe impl<T: ?Sized+?Move> Zeroable for $Ptr {
41+
#[inline]
42+
fn is_zero(&self) -> bool {
43+
// Cast because `is_null` is only available on thin pointers
44+
(*self as *mut u8).is_null()
45+
}
46+
}
3547
)+
3648
}
3749
}

src/libcore/ops/deref.rs

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[cfg(not(stage0))]
12+
use marker::Move;
13+
1114
/// Used for immutable dereferencing operations, like `*v`.
1215
///
1316
/// In addition to being used for explicit dereferencing operations with the
@@ -72,7 +75,12 @@
7275
pub trait Deref {
7376
/// The resulting type after dereferencing.
7477
#[stable(feature = "rust1", since = "1.0.0")]
78+
#[cfg(stage0)]
7579
type Target: ?Sized;
80+
/// The resulting type after dereferencing
81+
#[stable(feature = "rust1", since = "1.0.0")]
82+
#[cfg(not(stage0))]
83+
type Target: ?Sized+?Move;
7684

7785
/// Dereferences the value.
7886
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/ops/function.rs

+44
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[cfg(not(stage0))]
12+
use marker::Move;
13+
1114
/// The version of the call operator that takes an immutable receiver.
1215
///
1316
/// Instances of `Fn` can be called repeatedly without mutating state.
@@ -67,6 +70,18 @@
6770
#[stable(feature = "rust1", since = "1.0.0")]
6871
#[rustc_paren_sugar]
6972
#[fundamental] // so that regex can rely that `&str: !FnMut`
73+
#[cfg(not(stage0))]
74+
pub trait Fn<Args: ?Move> : FnMut<Args> {
75+
/// This is called when the call operator is used.
76+
#[unstable(feature = "fn_traits", issue = "29625")]
77+
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
78+
}
79+
/// docs
80+
#[lang = "fn"]
81+
#[stable(feature = "rust1", since = "1.0.0")]
82+
#[rustc_paren_sugar]
83+
#[fundamental] // so that regex can rely that `&str: !FnMut`
84+
#[cfg(stage0)]
7085
pub trait Fn<Args> : FnMut<Args> {
7186
/// Performs the call operation.
7287
#[unstable(feature = "fn_traits", issue = "29625")]
@@ -140,6 +155,18 @@ pub trait Fn<Args> : FnMut<Args> {
140155
#[stable(feature = "rust1", since = "1.0.0")]
141156
#[rustc_paren_sugar]
142157
#[fundamental] // so that regex can rely that `&str: !FnMut`
158+
#[cfg(not(stage0))]
159+
pub trait FnMut<Args: ?Move> : FnOnce<Args> {
160+
/// This is called when the call operator is used.
161+
#[unstable(feature = "fn_traits", issue = "29625")]
162+
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
163+
}
164+
/// docs
165+
#[lang = "fn_mut"]
166+
#[stable(feature = "rust1", since = "1.0.0")]
167+
#[rustc_paren_sugar]
168+
#[fundamental] // so that regex can rely that `&str: !FnMut`
169+
#[cfg(stage0)]
143170
pub trait FnMut<Args> : FnOnce<Args> {
144171
/// Performs the call operation.
145172
#[unstable(feature = "fn_traits", issue = "29625")]
@@ -213,6 +240,23 @@ pub trait FnMut<Args> : FnOnce<Args> {
213240
#[stable(feature = "rust1", since = "1.0.0")]
214241
#[rustc_paren_sugar]
215242
#[fundamental] // so that regex can rely that `&str: !FnMut`
243+
#[cfg(not(stage0))]
244+
pub trait FnOnce<Args: ?Move> {
245+
/// The returned type after the call operator is used.
246+
#[stable(feature = "fn_once_output", since = "1.12.0")]
247+
type Output: ?Move;
248+
249+
/// This is called when the call operator is used.
250+
#[unstable(feature = "fn_traits", issue = "29625")]
251+
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
252+
}
253+
254+
/// docs
255+
#[lang = "fn_once"]
256+
#[stable(feature = "rust1", since = "1.0.0")]
257+
#[rustc_paren_sugar]
258+
#[fundamental] // so that regex can rely that `&str: !FnMut`
259+
#[cfg(stage0)]
216260
pub trait FnOnce<Args> {
217261
/// The returned type after the call operator is used.
218262
#[stable(feature = "fn_once_output", since = "1.12.0")]

0 commit comments

Comments
 (0)