about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLuqman Aden <laden@csclub.uwaterloo.ca>2014-12-11 22:29:24 -0500
committerLuqman Aden <laden@csclub.uwaterloo.ca>2014-12-28 19:40:48 -0500
commitb44d7cb89c57b1fc0495b337dfddbe5cdc2ed6b2 (patch)
tree8b635a7045b5a8c0a153738a665b43a7107d6aa1 /src
parente83272b62883f97b8717a8150d894e89d7ae18d6 (diff)
downloadrust-b44d7cb89c57b1fc0495b337dfddbe5cdc2ed6b2.tar.gz
rust-b44d7cb89c57b1fc0495b337dfddbe5cdc2ed6b2.zip
Don't expose NonZero through libstd.
Diffstat (limited to 'src')
-rw-r--r--src/liballoc/arc.rs3
-rw-r--r--src/liballoc/rc.rs3
-rw-r--r--src/libcollections/vec.rs3
-rw-r--r--src/libcore/lib.rs1
-rw-r--r--src/libcore/nonzero.rs98
-rw-r--r--src/libcore/ptr.rs89
-rw-r--r--src/test/run-pass/enum-null-pointer-opt.rs4
7 files changed, 109 insertions, 92 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs
index 47e7ddac07c..3e235caab18 100644
--- a/src/liballoc/arc.rs
+++ b/src/liballoc/arc.rs
@@ -76,10 +76,11 @@ use core::default::Default;
 use core::kinds::{Sync, Send};
 use core::mem::{min_align_of, size_of, drop};
 use core::mem;
+use core::nonzero::NonZero;
 use core::ops::{Drop, Deref};
 use core::option::Option;
 use core::option::Option::{Some, None};
-use core::ptr::{mod, NonZero, RawPtr};
+use core::ptr::{mod, RawPtr};
 use heap::deallocate;
 
 /// An atomically reference counted wrapper for shared state.
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index 3d73c64bf4d..13dc4474c1a 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -150,10 +150,11 @@ use core::fmt;
 use core::hash::{mod, Hash};
 use core::kinds::marker;
 use core::mem::{transmute, min_align_of, size_of, forget};
+use core::nonzero::NonZero;
 use core::ops::{Deref, Drop};
 use core::option::Option;
 use core::option::Option::{Some, None};
-use core::ptr::{mod, NonZero, RawPtr};
+use core::ptr::{mod, RawPtr};
 use core::result::Result;
 use core::result::Result::{Ok, Err};
 
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs
index 6f618657280..f65527d3f66 100644
--- a/src/libcollections/vec.rs
+++ b/src/libcollections/vec.rs
@@ -56,9 +56,10 @@ use core::hash::{mod, Hash};
 use core::iter::repeat;
 use core::kinds::marker::{ContravariantLifetime, InvariantType};
 use core::mem;
+use core::nonzero::NonZero;
 use core::num::{Int, UnsignedInt};
 use core::ops;
-use core::ptr::{mod, NonZero};
+use core::ptr;
 use core::raw::Slice as RawSlice;
 use core::uint;
 
diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs
index 6d0d6e0817a..d646245510d 100644
--- a/src/libcore/lib.rs
+++ b/src/libcore/lib.rs
@@ -93,6 +93,7 @@ pub mod prelude;
 
 pub mod intrinsics;
 pub mod mem;
+pub mod nonzero;
 pub mod ptr;
 
 /* Core language traits */
diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs
new file mode 100644
index 00000000000..f976f08bf84
--- /dev/null
+++ b/src/libcore/nonzero.rs
@@ -0,0 +1,98 @@
+// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Exposes the NonZero lang item which provides optimization hints.
+
+use cmp::Eq;
+use intrinsics;
+use kinds::Copy;
+use ops::Deref;
+use option::Option;
+use option::Option::Some;
+use ptr::{null, null_mut, RawPtr, RawMutPtr};
+
+/// A wrapper type for raw pointers and integers that will never be
+/// NULL or 0 that might allow certain optimizations.
+#[lang="non_zero"]
+#[deriving(Clone, PartialEq, Eq, PartialOrd)]
+#[experimental]
+pub struct NonZero<T>(T);
+
+impl<T> NonZero<T> {
+    /// Create an instance of NonZero with the provided value.
+    /// You must indeed ensure that the value is actually "non-zero".
+    #[inline(always)]
+    pub unsafe fn new(inner: T) -> NonZero<T> {
+        NonZero(inner)
+    }
+}
+
+impl<T: Copy> Copy for NonZero<T> {}
+
+impl<T> Deref<T> for NonZero<T> {
+    #[inline]
+    fn deref<'a>(&'a self) -> &'a T {
+        let NonZero(ref inner) = *self;
+        inner
+    }
+}
+
+impl<T> RawPtr<T> for NonZero<*const T> {
+    #[inline]
+    fn null() -> NonZero<*const T> { NonZero(null()) }
+
+    #[inline]
+    fn is_null(&self) -> bool { false }
+
+    #[inline]
+    fn to_uint(&self) -> uint {
+        **self as uint
+    }
+
+    #[inline]
+    unsafe fn offset(self, count: int) -> NonZero<*const T> {
+        NonZero(intrinsics::offset(*self, count))
+    }
+
+    #[inline]
+    unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
+        Some(&***self)
+    }
+}
+
+impl<T> RawPtr<T> for NonZero<*mut T> {
+    #[inline]
+    fn null() -> NonZero<*mut T> { NonZero(null_mut()) }
+
+    #[inline]
+    fn is_null(&self) -> bool { false }
+
+    #[inline]
+    fn to_uint(&self) -> uint {
+        **self as uint
+    }
+
+    #[inline]
+    unsafe fn offset(self, count: int) -> NonZero<*mut T> {
+        NonZero(intrinsics::offset(*self as *const T, count) as *mut T)
+    }
+
+    #[inline]
+    unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
+        Some(&***self)
+    }
+}
+
+impl<T> RawMutPtr<T> for NonZero<*mut T> {
+    #[inline]
+    unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> {
+        Some(&mut ***self)
+    }
+}
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index 23eb117680a..8c724b4d852 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -90,8 +90,7 @@
 use mem;
 use clone::Clone;
 use intrinsics;
-use kinds::{Copy, Send, Sync};
-use ops::Deref;
+use kinds::{Send, Sync};
 use option::Option;
 use option::Option::{Some, None};
 
@@ -111,32 +110,6 @@ pub use intrinsics::copy_memory;
 pub use intrinsics::set_memory;
 
 
-/// A wrapper type for raw pointers and integers that will never be
-/// NULL or 0 that might allow certain optimizations.
-#[lang="non_zero"]
-#[deriving(Clone, PartialEq, Eq, PartialOrd)]
-#[experimental]
-pub struct NonZero<T>(T);
-
-impl<T> NonZero<T> {
-    /// Create an instance of NonZero with the provided value.
-    /// You must indeed ensure that the value is actually "non-zero".
-    #[inline(always)]
-    pub unsafe fn new(inner: T) -> NonZero<T> {
-        NonZero(inner)
-    }
-}
-
-impl<T> Deref<T> for NonZero<T> {
-    #[inline]
-    fn deref<'a>(&'a self) -> &'a T {
-        let NonZero(ref inner) = *self;
-        inner
-    }
-}
-
-impl<T: Copy> Copy for NonZero<T> {}
-
 /// Creates a null raw pointer.
 ///
 /// # Examples
@@ -341,32 +314,6 @@ impl<T> RawPtr<T> for *const T {
     }
 }
 
-impl<T> RawPtr<T> for NonZero<*const T> {
-    #[inline]
-    fn null() -> NonZero<*const T> { NonZero(null()) }
-
-    #[inline]
-    fn is_null(&self) -> bool { false }
-
-    #[inline]
-    fn to_uint(&self) -> uint {
-        let NonZero(p) = *self;
-        p as uint
-    }
-
-    #[inline]
-    unsafe fn offset(self, count: int) -> NonZero<*const T> {
-        let NonZero(p) = self;
-        NonZero(intrinsics::offset(p, count))
-    }
-
-    #[inline]
-    unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
-        let NonZero(p) = *self;
-        Some(&*p)
-    }
-}
-
 impl<T> RawPtr<T> for *mut T {
     #[inline]
     fn null() -> *mut T { null_mut() }
@@ -392,32 +339,6 @@ impl<T> RawPtr<T> for *mut T {
     }
 }
 
-impl<T> RawPtr<T> for NonZero<*mut T> {
-    #[inline]
-    fn null() -> NonZero<*mut T> { NonZero(null_mut()) }
-
-    #[inline]
-    fn is_null(&self) -> bool { false }
-
-    #[inline]
-    fn to_uint(&self) -> uint {
-        let NonZero(p) = *self;
-        p as uint
-    }
-
-    #[inline]
-    unsafe fn offset(self, count: int) -> NonZero<*mut T> {
-        let NonZero(p) = self;
-        NonZero(intrinsics::offset(p as *const T, count) as *mut T)
-    }
-
-    #[inline]
-    unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
-        let NonZero(p) = *self;
-        Some(&*p)
-    }
-}
-
 impl<T> RawMutPtr<T> for *mut T {
     #[inline]
     unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> {
@@ -429,14 +350,6 @@ impl<T> RawMutPtr<T> for *mut T {
     }
 }
 
-impl<T> RawMutPtr<T> for NonZero<*mut T> {
-    #[inline]
-    unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> {
-        let NonZero(p) = *self;
-        Some(&mut *p)
-    }
-}
-
 // Equality for pointers
 impl<T> PartialEq for *const T {
     #[inline]
diff --git a/src/test/run-pass/enum-null-pointer-opt.rs b/src/test/run-pass/enum-null-pointer-opt.rs
index f0e34f0dc4b..d8d74c8bb45 100644
--- a/src/test/run-pass/enum-null-pointer-opt.rs
+++ b/src/test/run-pass/enum-null-pointer-opt.rs
@@ -9,8 +9,10 @@
 // except according to those terms.
 
 
+extern crate core;
+
+use core::nonzero::NonZero;
 use std::mem::size_of;
-use std::ptr::NonZero;
 use std::rc::Rc;
 use std::sync::Arc;