diff options
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/marker.rs | 2 | ||||
| -rw-r--r-- | src/libcore/nonzero.rs | 9 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 3bcdfabbb24..23f07773f3f 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -596,7 +596,7 @@ mod impls { /// This affects, for example, whether a `static` of that type is /// placed in read-only static memory or writable static memory. #[lang = "freeze"] -unsafe auto trait Freeze {} +pub(crate) unsafe auto trait Freeze {} impl<T: ?Sized> !Freeze for UnsafeCell<T> {} unsafe impl<T: ?Sized> Freeze for PhantomData<T> {} diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs index 22d93a5301e..a89c6ca60cb 100644 --- a/src/libcore/nonzero.rs +++ b/src/libcore/nonzero.rs @@ -11,22 +11,23 @@ //! Exposes the NonZero lang item which provides optimization hints. use ops::{CoerceUnsized, DispatchFromDyn}; +use marker::Freeze; /// A wrapper type for raw pointers and integers that will never be /// NULL or 0 that might allow certain optimizations. #[rustc_layout_scalar_valid_range_start(1)] #[derive(Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] #[repr(transparent)] -pub(crate) struct NonZero<T>(pub(crate) T); +pub(crate) struct NonZero<T: Freeze>(pub(crate) T); // Do not call `T::clone` as theoretically it could turn the field into `0` // invalidating `NonZero`'s invariant. -impl<T: Copy> Clone for NonZero<T> { +impl<T: Copy + Freeze> Clone for NonZero<T> { fn clone(&self) -> Self { unsafe { NonZero(self.0) } } } -impl<T: CoerceUnsized<U>, U> CoerceUnsized<NonZero<U>> for NonZero<T> {} +impl<T: CoerceUnsized<U> + Freeze, U: Freeze> CoerceUnsized<NonZero<U>> for NonZero<T> {} -impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<NonZero<U>> for NonZero<T> {} +impl<T: DispatchFromDyn<U> + Freeze, U: Freeze> DispatchFromDyn<NonZero<U>> for NonZero<T> {} |
