Skip to content

Commit 530d7bc

Browse files
committed
Add #[repr(transparent)] to some libcore types
* `UnsafeCell` * `Cell` * `NonZero*` * `NonNull` * `Unique`
1 parent 2532056 commit 530d7bc

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
}
@@ -1282,6 +1283,7 @@ impl<'a, T: ?Sized + fmt::Display> fmt::Display for RefMut<'a, T> {
12821283
/// ```
12831284
#[lang = "unsafe_cell"]
12841285
#[stable(feature = "rust1", since = "1.0.0")]
1286+
#[repr(transparent)]
12851287
pub struct UnsafeCell<T: ?Sized> {
12861288
value: T,
12871289
}

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
#![feature(const_slice_len)]
125125
#![feature(const_str_as_bytes)]
126126
#![feature(const_str_len)]
127+
#![cfg_attr(stage0, feature(repr_transparent))]
127128

128129
#[prelude_import]
129130
#[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
@@ -2692,6 +2692,7 @@ impl<T: ?Sized> PartialOrd for *mut T {
26922692
reason = "use NonNull instead and consider PhantomData<T> \
26932693
(if you also use #[may_dangle]), Send, and/or Sync")]
26942694
#[doc(hidden)]
2695+
#[repr(transparent)]
26952696
pub struct Unique<T: ?Sized> {
26962697
pointer: NonZero<*const T>,
26972698
// NOTE: this marker has no consequences for variance, but is necessary
@@ -2840,6 +2841,7 @@ impl<'a, T: ?Sized> From<NonNull<T>> for Unique<T> {
28402841
/// such as Box, Rc, Arc, Vec, and LinkedList. This is the case because they
28412842
/// provide a public API that follows the normal shared XOR mutable rules of Rust.
28422843
#[stable(feature = "nonnull", since = "1.25.0")]
2844+
#[repr(transparent)]
28432845
pub struct NonNull<T: ?Sized> {
28442846
pointer: NonZero<*const T>,
28452847
}

0 commit comments

Comments
 (0)