Add #[repr(transparent)] to some libcore types

* `UnsafeCell`
* `Cell`
* `NonZero*`
* `NonNull`
* `Unique`
This commit is contained in:
Simon Sapin
2018-06-06 13:30:35 +02:00
parent 253205658e
commit 530d7bc517
5 changed files with 8 additions and 0 deletions
+2
View File
@@ -235,6 +235,7 @@
///
/// 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>,
}
@@ -1282,6 +1283,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
/// ```
#[lang = "unsafe_cell"]
#[stable(feature = "rust1", since = "1.0.0")]
#[repr(transparent)]
pub struct UnsafeCell<T: ?Sized> {
value: T,
}
+1
View File
@@ -124,6 +124,7 @@
#![feature(const_slice_len)]
#![feature(const_str_as_bytes)]
#![feature(const_str_len)]
#![cfg_attr(stage0, feature(repr_transparent))]
#[prelude_import]
#[allow(unused)]
+1
View File
@@ -16,6 +16,7 @@
/// 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> {}
+2
View File
@@ -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 @@ pub fn get(self) -> $Int {
/// ```
#[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);
+2
View File
@@ -2692,6 +2692,7 @@ fn ge(&self, other: &*mut T) -> bool { *self >= *other }
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
@@ -2840,6 +2841,7 @@ fn from(p: NonNull<T>) -> Self {
/// 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>,
}