diff options
| author | bors <bors@rust-lang.org> | 2018-07-04 16:21:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-07-04 16:21:42 +0000 |
| commit | 0ad8f9e5b1950e4ac09950def4231c8d5875de57 (patch) | |
| tree | 1447e7b31c5844fb8762c0ed0cfc12f607694c68 | |
| parent | eded1aa14cb322b3b1000ee98ea9ba3a10dacba1 (diff) | |
| parent | 530d7bc5174e93682a38b22ac7ff4e3569bcd813 (diff) | |
| download | rust-0ad8f9e5b1950e4ac09950def4231c8d5875de57.tar.gz rust-0ad8f9e5b1950e4ac09950def4231c8d5875de57.zip | |
Auto merge of #51395 - SimonSapin:repr-transparent, r=SimonSapin
Add #[repr(transparent)] to some libcore types * `UnsafeCell` * `Cell` * `NonZero*` * `NonNull` * `Unique` CC https://github.com/rust-lang/rust/issues/43036
| -rw-r--r-- | src/libcore/cell.rs | 2 | ||||
| -rw-r--r-- | src/libcore/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcore/nonzero.rs | 1 | ||||
| -rw-r--r-- | src/libcore/num/mod.rs | 2 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 2 |
5 files changed, 8 insertions, 0 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 21edc6dfee4..2292617f51e 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -235,6 +235,7 @@ use ptr; /// /// See the [module-level documentation](index.html) for more. #[stable(feature = "rust1", since = "1.0.0")] +#[repr(transparent)] pub struct Cell<T> { value: UnsafeCell<T>, } @@ -1395,6 +1396,7 @@ impl<'a, T: ?Sized + fmt::Display> fmt::Display for RefMut<'a, T> { /// ``` #[lang = "unsafe_cell"] #[stable(feature = "rust1", since = "1.0.0")] +#[repr(transparent)] pub struct UnsafeCell<T: ?Sized> { value: T, } diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index bbe6ae8619f..b2b38820a89 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -122,6 +122,7 @@ #![feature(const_slice_len)] #![feature(const_str_as_bytes)] #![feature(const_str_len)] +#![cfg_attr(stage0, feature(repr_transparent))] #[prelude_import] #[allow(unused)] diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs index ee5230cef8d..cc36ea7f713 100644 --- a/src/libcore/nonzero.rs +++ b/src/libcore/nonzero.rs @@ -16,6 +16,7 @@ use ops::CoerceUnsized; /// NULL or 0 that might allow certain optimizations. #[lang = "non_zero"] #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[repr(transparent)] pub(crate) struct NonZero<T>(pub(crate) T); impl<T: CoerceUnsized<U>, U> CoerceUnsized<NonZero<U>> for NonZero<T> {} diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 260ebabf1fa..0b8f8f0703d 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -48,6 +48,7 @@ macro_rules! nonzero_integers { /// ``` #[stable(feature = "nonzero", since = "1.28.0")] #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] + #[repr(transparent)] pub struct $Ty(NonZero<$Int>); impl $Ty { @@ -123,6 +124,7 @@ nonzero_integers! { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)] +#[repr(transparent)] pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T); diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 164b29d3515..0af642258c2 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2665,6 +2665,7 @@ impl<T: ?Sized> PartialOrd for *mut T { reason = "use NonNull instead and consider PhantomData<T> \ (if you also use #[may_dangle]), Send, and/or Sync")] #[doc(hidden)] +#[repr(transparent)] pub struct Unique<T: ?Sized> { pointer: NonZero<*const T>, // NOTE: this marker has no consequences for variance, but is necessary @@ -2813,6 +2814,7 @@ impl<'a, T: ?Sized> From<NonNull<T>> for Unique<T> { /// such as Box, Rc, Arc, Vec, and LinkedList. This is the case because they /// provide a public API that follows the normal shared XOR mutable rules of Rust. #[stable(feature = "nonnull", since = "1.25.0")] +#[repr(transparent)] pub struct NonNull<T: ?Sized> { pointer: NonZero<*const T>, } |
