about summary refs log tree commit diff
path: root/src/libcore/nonzero.rs
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2018-02-16 11:33:22 +0100
committerSimon Sapin <simon.sapin@exyr.org>2018-05-16 19:08:41 +0200
commitee85bfdcc23de49bbc565142efff87b14a7fc775 (patch)
tree9164f38859cb5d230e1c7140134e07239a7bb3d5 /src/libcore/nonzero.rs
parent2a3f5367a23a769a068c37460db336de427c4b48 (diff)
downloadrust-ee85bfdcc23de49bbc565142efff87b14a7fc775.tar.gz
rust-ee85bfdcc23de49bbc565142efff87b14a7fc775.zip
Make core::nonzero private
It is now an implementation detail of ptr::NonNull and num::NonZero*
Diffstat (limited to 'src/libcore/nonzero.rs')
-rw-r--r--src/libcore/nonzero.rs96
1 files changed, 3 insertions, 93 deletions
diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs
index 19836d98844..ee5230cef8d 100644
--- a/src/libcore/nonzero.rs
+++ b/src/libcore/nonzero.rs
@@ -9,103 +9,13 @@
 // except according to those terms.
 
 //! Exposes the NonZero lang item which provides optimization hints.
-#![unstable(feature = "nonzero", reason = "deprecated", issue = "49137")]
-#![rustc_deprecated(reason = "use `std::ptr::NonNull` or `std::num::NonZero*` instead",
-                    since = "1.26.0")]
-#![allow(deprecated)]
 
 use ops::CoerceUnsized;
 
-/// Unsafe trait to indicate what types are usable with the NonZero struct
-pub unsafe trait Zeroable {
-    /// Whether this value is zero
-    fn is_zero(&self) -> bool;
-}
-
-macro_rules! impl_zeroable_for_pointer_types {
-    ( $( $Ptr: ty )+ ) => {
-        $(
-            /// For fat pointers to be considered "zero", only the "data" part needs to be null.
-            unsafe impl<T: ?Sized> Zeroable for $Ptr {
-                #[inline]
-                fn is_zero(&self) -> bool {
-                    (*self).is_null()
-                }
-            }
-        )+
-    }
-}
-
-macro_rules! impl_zeroable_for_integer_types {
-    ( $( $Int: ty )+ ) => {
-        $(
-            unsafe impl Zeroable for $Int {
-                #[inline]
-                fn is_zero(&self) -> bool {
-                    *self == 0
-                }
-            }
-        )+
-    }
-}
-
-impl_zeroable_for_pointer_types! {
-    *const T
-    *mut T
-}
-
-impl_zeroable_for_integer_types! {
-    usize u8 u16 u32 u64 u128
-    isize i8 i16 i32 i64 i128
-}
-
 /// A wrapper type for raw pointers and integers that will never be
 /// NULL or 0 that might allow certain optimizations.
 #[lang = "non_zero"]
-#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
-pub struct NonZero<T: Zeroable>(pub(crate) T);
-
-impl<T: Zeroable> NonZero<T> {
-    /// Creates an instance of NonZero with the provided value.
-    /// You must indeed ensure that the value is actually "non-zero".
-    #[inline]
-    pub const unsafe fn new_unchecked(inner: T) -> Self {
-        NonZero(inner)
-    }
-
-    /// Creates an instance of NonZero with the provided value.
-    #[inline]
-    pub fn new(inner: T) -> Option<Self> {
-        if inner.is_zero() {
-            None
-        } else {
-            Some(NonZero(inner))
-        }
-    }
-
-    /// Gets the inner value.
-    pub fn get(self) -> T {
-        self.0
-    }
-}
-
-impl<T: Zeroable+CoerceUnsized<U>, U: Zeroable> CoerceUnsized<NonZero<U>> for NonZero<T> {}
-
-impl<'a, T: ?Sized> From<&'a mut T> for NonZero<*mut T> {
-    fn from(reference: &'a mut T) -> Self {
-        NonZero(reference)
-    }
-}
-
-impl<'a, T: ?Sized> From<&'a mut T> for NonZero<*const T> {
-    fn from(reference: &'a mut T) -> Self {
-        let ptr: *mut T = reference;
-        NonZero(ptr)
-    }
-}
+#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
+pub(crate) struct NonZero<T>(pub(crate) T);
 
-impl<'a, T: ?Sized> From<&'a T> for NonZero<*const T> {
-    fn from(reference: &'a T) -> Self {
-        NonZero(reference)
-    }
-}
+impl<T: CoerceUnsized<U>, U> CoerceUnsized<NonZero<U>> for NonZero<T> {}