Skip to content

Commit 0ad8f9e

Browse files
committed
Auto merge of #51395 - SimonSapin:repr-transparent, r=SimonSapin
Add #[repr(transparent)] to some libcore types * `UnsafeCell` * `Cell` * `NonZero*` * `NonNull` * `Unique` CC #43036
2 parents eded1aa + 530d7bc commit 0ad8f9e

File tree

5 files changed

+8
-0
lines changed

5 files changed

+8
-0
lines changed

src/libcore/cell.rs

+2
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ use ptr;
235235
///
236236
/// See the [module-level documentation](index.html) for more.
237237
#[stable(feature = "rust1", since = "1.0.0")]
238+
#[repr(transparent)]
238239
pub struct Cell<T> {
239240
value: UnsafeCell<T>,
240241
}
@@ -1395,6 +1396,7 @@ impl<'a, T: ?Sized + fmt::Display> fmt::Display for RefMut<'a, T> {
13951396
/// ```
13961397
#[lang = "unsafe_cell"]
13971398
#[stable(feature = "rust1", since = "1.0.0")]
1399+
#[repr(transparent)]
13981400
pub struct UnsafeCell<T: ?Sized> {
13991401
value: T,
14001402
}

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
#![feature(const_slice_len)]
123123
#![feature(const_str_as_bytes)]
124124
#![feature(const_str_len)]
125+
#![cfg_attr(stage0, feature(repr_transparent))]
125126

126127
#[prelude_import]
127128
#[allow(unused)]

src/libcore/nonzero.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use ops::CoerceUnsized;
1616
/// NULL or 0 that might allow certain optimizations.
1717
#[lang = "non_zero"]
1818
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
19+
#[repr(transparent)]
1920
pub(crate) struct NonZero<T>(pub(crate) T);
2021

2122
impl<T: CoerceUnsized<U>, U> CoerceUnsized<NonZero<U>> for NonZero<T> {}

src/libcore/num/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ macro_rules! nonzero_integers {
4848
/// ```
4949
#[stable(feature = "nonzero", since = "1.28.0")]
5050
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
51+
#[repr(transparent)]
5152
pub struct $Ty(NonZero<$Int>);
5253

5354
impl $Ty {
@@ -123,6 +124,7 @@ nonzero_integers! {
123124
/// ```
124125
#[stable(feature = "rust1", since = "1.0.0")]
125126
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)]
127+
#[repr(transparent)]
126128
pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")]
127129
pub T);
128130

src/libcore/ptr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2665,6 +2665,7 @@ impl<T: ?Sized> PartialOrd for *mut T {
26652665
reason = "use NonNull instead and consider PhantomData<T> \
26662666
(if you also use #[may_dangle]), Send, and/or Sync")]
26672667
#[doc(hidden)]
2668+
#[repr(transparent)]
26682669
pub struct Unique<T: ?Sized> {
26692670
pointer: NonZero<*const T>,
26702671
// 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> {
28132814
/// such as Box, Rc, Arc, Vec, and LinkedList. This is the case because they
28142815
/// provide a public API that follows the normal shared XOR mutable rules of Rust.
28152816
#[stable(feature = "nonnull", since = "1.25.0")]
2817+
#[repr(transparent)]
28162818
pub struct NonNull<T: ?Sized> {
28172819
pointer: NonZero<*const T>,
28182820
}

0 commit comments

Comments
 (0)