about summary refs log tree commit diff
diff options
context:
space:
mode:
m---------src/doc/nomicon0
-rw-r--r--src/liballoc/allocator.rs6
-rw-r--r--src/liballoc/arc.rs6
-rw-r--r--src/liballoc/btree/node.rs10
-rw-r--r--src/liballoc/linked_list.rs6
-rw-r--r--src/liballoc/raw_vec.rs6
-rw-r--r--src/liballoc/rc.rs10
-rw-r--r--src/liballoc/vec.rs4
-rw-r--r--src/liballoc/vec_deque.rs2
-rw-r--r--src/libcore/nonzero.rs2
-rw-r--r--src/libcore/ptr.rs12
-rw-r--r--src/libcore/tests/nonzero.rs6
-rw-r--r--src/libcore/tests/ptr.rs2
-rw-r--r--src/librustc/ty/subst.rs4
-rw-r--r--src/librustc_data_structures/array_vec.rs2
-rw-r--r--src/librustc_data_structures/obligation_forest/node_index.rs2
-rw-r--r--src/librustc_mir/dataflow/move_paths/mod.rs2
-rw-r--r--src/libstd/collections/hash/table.rs6
-rw-r--r--src/test/run-pass/issue-23433.rs2
-rw-r--r--src/test/ui/print_type_sizes/nullable.rs2
20 files changed, 46 insertions, 46 deletions
diff --git a/src/doc/nomicon b/src/doc/nomicon
-Subproject 81134a4dff811403b3b2f349b0c59a819f0fe0c
+Subproject f8fd6710399a1a557155cb5be4922fe6a6f694c
diff --git a/src/liballoc/allocator.rs b/src/liballoc/allocator.rs
index ca5388b4701..efc59d2cbc8 100644
--- a/src/liballoc/allocator.rs
+++ b/src/liballoc/allocator.rs
@@ -892,7 +892,7 @@ pub unsafe trait Alloc {
     {
         let k = Layout::new::<T>();
         if k.size() > 0 {
-            unsafe { self.alloc(k).map(|p| Unique::new(p as *mut T)) }
+            unsafe { self.alloc(k).map(|p| Unique::new_unchecked(p as *mut T)) }
         } else {
             Err(AllocErr::invalid_input("zero-sized type invalid for alloc_one"))
         }
@@ -963,7 +963,7 @@ pub unsafe trait Alloc {
                 unsafe {
                     self.alloc(layout.clone())
                         .map(|p| {
-                            Unique::new(p as *mut T)
+                            Unique::new_unchecked(p as *mut T)
                         })
                 }
             }
@@ -1012,7 +1012,7 @@ pub unsafe trait Alloc {
         match (Layout::array::<T>(n_old), Layout::array::<T>(n_new), ptr.as_ptr()) {
             (Some(ref k_old), Some(ref k_new), ptr) if k_old.size() > 0 && k_new.size() > 0 => {
                 self.realloc(ptr as *mut u8, k_old.clone(), k_new.clone())
-                    .map(|p|Unique::new(p as *mut T))
+                    .map(|p|Unique::new_unchecked(p as *mut T))
             }
             _ => {
                 Err(AllocErr::invalid_input("invalid layout for realloc_array"))
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs
index 85c7efb7ac5..cc792c9f83f 100644
--- a/src/liballoc/arc.rs
+++ b/src/liballoc/arc.rs
@@ -280,7 +280,7 @@ impl<T> Arc<T> {
             weak: atomic::AtomicUsize::new(1),
             data: data,
         };
-        Arc { ptr: unsafe { Shared::new(Box::into_raw(x)) } }
+        Arc { ptr: unsafe { Shared::new_unchecked(Box::into_raw(x)) } }
     }
 
     /// Returns the contained value, if the `Arc` has exactly one strong reference.
@@ -382,7 +382,7 @@ impl<T> Arc<T> {
         // `data` field from the pointer.
         let ptr = (ptr as *const u8).offset(-offset_of!(ArcInner<T>, data));
         Arc {
-            ptr: Shared::new(ptr as *mut u8 as *mut _),
+            ptr: Shared::new_unchecked(ptr as *mut u8 as *mut _),
         }
     }
 }
@@ -842,7 +842,7 @@ impl<T> Weak<T> {
     pub fn new() -> Weak<T> {
         unsafe {
             Weak {
-                ptr: Shared::new(Box::into_raw(box ArcInner {
+                ptr: Shared::new_unchecked(Box::into_raw(box ArcInner {
                     strong: atomic::AtomicUsize::new(0),
                     weak: atomic::AtomicUsize::new(1),
                     data: uninitialized(),
diff --git a/src/liballoc/btree/node.rs b/src/liballoc/btree/node.rs
index 0eaff6f2192..0a752702b12 100644
--- a/src/liballoc/btree/node.rs
+++ b/src/liballoc/btree/node.rs
@@ -141,23 +141,23 @@ struct BoxedNode<K, V> {
 impl<K, V> BoxedNode<K, V> {
     fn from_leaf(node: Box<LeafNode<K, V>>) -> Self {
         unsafe {
-            BoxedNode { ptr: Unique::new(Box::into_raw(node)) }
+            BoxedNode { ptr: Unique::new_unchecked(Box::into_raw(node)) }
         }
     }
 
     fn from_internal(node: Box<InternalNode<K, V>>) -> Self {
         unsafe {
-            BoxedNode { ptr: Unique::new(Box::into_raw(node) as *mut LeafNode<K, V>) }
+            BoxedNode { ptr: Unique::new_unchecked(Box::into_raw(node) as *mut LeafNode<K, V>) }
         }
     }
 
     unsafe fn from_ptr(ptr: NonZero<*const LeafNode<K, V>>) -> Self {
-        BoxedNode { ptr: Unique::new(ptr.get() as *mut LeafNode<K, V>) }
+        BoxedNode { ptr: Unique::new_unchecked(ptr.get() as *mut LeafNode<K, V>) }
     }
 
     fn as_ptr(&self) -> NonZero<*const LeafNode<K, V>> {
         unsafe {
-            NonZero::new(self.ptr.as_ptr())
+            NonZero::new_unchecked(self.ptr.as_ptr())
         }
     }
 }
@@ -391,7 +391,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
                 node: NodeRef {
                     height: self.height + 1,
                     node: unsafe {
-                        NonZero::new(self.as_leaf().parent as *mut LeafNode<K, V>)
+                        NonZero::new_unchecked(self.as_leaf().parent as *mut LeafNode<K, V>)
                     },
                     root: self.root,
                     _marker: PhantomData
diff --git a/src/liballoc/linked_list.rs b/src/liballoc/linked_list.rs
index e8973b7d285..08d6fac3849 100644
--- a/src/liballoc/linked_list.rs
+++ b/src/liballoc/linked_list.rs
@@ -157,7 +157,7 @@ impl<T> LinkedList<T> {
         unsafe {
             node.next = self.head;
             node.prev = None;
-            let node = Some(Shared::new(Box::into_raw(node)));
+            let node = Some(Shared::new_unchecked(Box::into_raw(node)));
 
             match self.head {
                 None => self.tail = node,
@@ -192,7 +192,7 @@ impl<T> LinkedList<T> {
         unsafe {
             node.next = None;
             node.prev = self.tail;
-            let node = Some(Shared::new(Box::into_raw(node)));
+            let node = Some(Shared::new_unchecked(Box::into_raw(node)));
 
             match self.tail {
                 None => self.head = node,
@@ -921,7 +921,7 @@ impl<'a, T> IterMut<'a, T> {
                     Some(prev) => prev,
                 };
 
-                let node = Some(Shared::new(Box::into_raw(box Node {
+                let node = Some(Shared::new_unchecked(Box::into_raw(box Node {
                     next: Some(head),
                     prev: Some(prev),
                     element: element,
diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs
index d1aab4c70be..ca55831220d 100644
--- a/src/liballoc/raw_vec.rs
+++ b/src/liballoc/raw_vec.rs
@@ -104,7 +104,7 @@ impl<T, A: Alloc> RawVec<T, A> {
             };
 
             RawVec {
-                ptr: Unique::new(ptr as *mut _),
+                ptr: Unique::new_unchecked(ptr as *mut _),
                 cap: cap,
                 a: a,
             }
@@ -159,7 +159,7 @@ impl<T, A: Alloc> RawVec<T, A> {
     /// If the ptr and capacity come from a RawVec created via `a`, then this is guaranteed.
     pub unsafe fn from_raw_parts_in(ptr: *mut T, cap: usize, a: A) -> Self {
         RawVec {
-            ptr: Unique::new(ptr),
+            ptr: Unique::new_unchecked(ptr),
             cap: cap,
             a: a,
         }
@@ -176,7 +176,7 @@ impl<T> RawVec<T, Heap> {
     /// If the ptr and capacity come from a RawVec, then this is guaranteed.
     pub unsafe fn from_raw_parts(ptr: *mut T, cap: usize) -> Self {
         RawVec {
-            ptr: Unique::new(ptr),
+            ptr: Unique::new_unchecked(ptr),
             cap: cap,
             a: Heap,
         }
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index 9e72238fbd4..6ff6b6b0372 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -309,7 +309,7 @@ impl<T> Rc<T> {
                 // pointers, which ensures that the weak destructor never frees
                 // the allocation while the strong destructor is running, even
                 // if the weak pointer is stored inside the strong one.
-                ptr: Shared::new(Box::into_raw(box RcBox {
+                ptr: Shared::new_unchecked(Box::into_raw(box RcBox {
                     strong: Cell::new(1),
                     weak: Cell::new(1),
                     value: value,
@@ -418,7 +418,7 @@ impl<T> Rc<T> {
 
         let ptr = (ptr as *const u8).offset(-offset_of!(RcBox<T>, value));
         Rc {
-            ptr: Shared::new(ptr as *mut u8 as *mut _)
+            ptr: Shared::new_unchecked(ptr as *mut u8 as *mut _)
         }
     }
 }
@@ -443,7 +443,7 @@ impl Rc<str> {
             // Combine the allocation address and the string length into a fat pointer to `RcBox`.
             let rcbox_ptr: *mut RcBox<str> = mem::transmute([ptr as usize, value.len()]);
             assert!(aligned_len * size_of::<usize>() == size_of_val(&*rcbox_ptr));
-            Rc { ptr: Shared::new(rcbox_ptr) }
+            Rc { ptr: Shared::new_unchecked(rcbox_ptr) }
         }
     }
 }
@@ -476,7 +476,7 @@ impl<T> Rc<[T]> {
             // Free the original allocation without freeing its (moved) contents.
             box_free(Box::into_raw(value));
 
-            Rc { ptr: Shared::new(ptr as *mut _) }
+            Rc { ptr: Shared::new_unchecked(ptr as *mut _) }
         }
     }
 }
@@ -1016,7 +1016,7 @@ impl<T> Weak<T> {
     pub fn new() -> Weak<T> {
         unsafe {
             Weak {
-                ptr: Shared::new(Box::into_raw(box RcBox {
+                ptr: Shared::new_unchecked(Box::into_raw(box RcBox {
                     strong: Cell::new(0),
                     weak: Cell::new(1),
                     value: uninitialized(),
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index 780a51aec3b..bc1521c4069 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -1126,7 +1126,7 @@ impl<T> Vec<T> {
                 tail_start: end,
                 tail_len: len - end,
                 iter: range_slice.iter(),
-                vec: Shared::new(self as *mut _),
+                vec: Shared::new_unchecked(self as *mut _),
             }
         }
     }
@@ -1727,7 +1727,7 @@ impl<T> IntoIterator for Vec<T> {
             let cap = self.buf.cap();
             mem::forget(self);
             IntoIter {
-                buf: Shared::new(begin),
+                buf: Shared::new_unchecked(begin),
                 cap: cap,
                 ptr: begin,
                 end: end,
diff --git a/src/liballoc/vec_deque.rs b/src/liballoc/vec_deque.rs
index 18175a5d01b..a99b7bbe053 100644
--- a/src/liballoc/vec_deque.rs
+++ b/src/liballoc/vec_deque.rs
@@ -893,7 +893,7 @@ impl<T> VecDeque<T> {
         self.head = drain_tail;
 
         Drain {
-            deque: unsafe { Shared::new(self as *mut _) },
+            deque: unsafe { Shared::new_unchecked(self as *mut _) },
             after_tail: drain_head,
             after_head: head,
             iter: Iter {
diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs
index 0564d73dd6d..6acdcad8763 100644
--- a/src/libcore/nonzero.rs
+++ b/src/libcore/nonzero.rs
@@ -69,7 +69,7 @@ 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(inner: T) -> Self {
+    pub const unsafe fn new_unchecked(inner: T) -> Self {
         NonZero(inner)
     }
 
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index e83ca63834a..5ece63e23b1 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -1098,7 +1098,7 @@ impl<T: Sized> Unique<T> {
     pub fn empty() -> Self {
         unsafe {
             let ptr = mem::align_of::<T>() as *mut T;
-            Unique::new(ptr)
+            Unique::new_unchecked(ptr)
         }
     }
 }
@@ -1110,8 +1110,8 @@ impl<T: ?Sized> Unique<T> {
     /// # Safety
     ///
     /// `ptr` must be non-null.
-    pub const unsafe fn new(ptr: *mut T) -> Self {
-        Unique { pointer: NonZero::new(ptr), _marker: PhantomData }
+    pub const unsafe fn new_unchecked(ptr: *mut T) -> Self {
+        Unique { pointer: NonZero::new_unchecked(ptr), _marker: PhantomData }
     }
 
     /// Creates a new `Unique` if `ptr` is non-null.
@@ -1217,7 +1217,7 @@ impl<T: Sized> Shared<T> {
     pub fn empty() -> Self {
         unsafe {
             let ptr = mem::align_of::<T>() as *mut T;
-            Shared::new(ptr)
+            Shared::new_unchecked(ptr)
         }
     }
 }
@@ -1229,8 +1229,8 @@ impl<T: ?Sized> Shared<T> {
     /// # Safety
     ///
     /// `ptr` must be non-null.
-    pub const unsafe fn new(ptr: *mut T) -> Self {
-        Shared { pointer: NonZero::new(ptr), _marker: PhantomData }
+    pub const unsafe fn new_unchecked(ptr: *mut T) -> Self {
+        Shared { pointer: NonZero::new_unchecked(ptr), _marker: PhantomData }
     }
 
     /// Creates a new `Shared` if `ptr` is non-null.
diff --git a/src/libcore/tests/nonzero.rs b/src/libcore/tests/nonzero.rs
index 588fffda35f..a795dd57504 100644
--- a/src/libcore/tests/nonzero.rs
+++ b/src/libcore/tests/nonzero.rs
@@ -16,7 +16,7 @@ use std::mem::size_of;
 #[test]
 fn test_create_nonzero_instance() {
     let _a = unsafe {
-        NonZero::new(21)
+        NonZero::new_unchecked(21)
     };
 }
 
@@ -28,14 +28,14 @@ fn test_size_nonzero_in_option() {
 #[test]
 fn test_match_on_nonzero_option() {
     let a = Some(unsafe {
-        NonZero::new(42)
+        NonZero::new_unchecked(42)
     });
     match a {
         Some(val) => assert_eq!(val.get(), 42),
         None => panic!("unexpected None while matching on Some(NonZero(_))")
     }
 
-    match unsafe { Some(NonZero::new(43)) } {
+    match unsafe { Some(NonZero::new_unchecked(43)) } {
         Some(val) => assert_eq!(val.get(), 43),
         None => panic!("unexpected None while matching on Some(NonZero(_))")
     }
diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs
index e28dc6a6881..c2d53840f8f 100644
--- a/src/libcore/tests/ptr.rs
+++ b/src/libcore/tests/ptr.rs
@@ -167,7 +167,7 @@ fn test_set_memory() {
 #[test]
 fn test_unsized_unique() {
     let xs: &[i32] = &[1, 2, 3];
-    let ptr = unsafe { Unique::new(xs as *const [i32] as *mut [i32]) };
+    let ptr = unsafe { Unique::new_unchecked(xs as *const [i32] as *mut [i32]) };
     let ys = unsafe { ptr.as_ref() };
     let zs: &[i32] = &[1, 2, 3];
     assert!(ys == zs);
diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs
index f6112d4887d..e2881ac9b79 100644
--- a/src/librustc/ty/subst.rs
+++ b/src/librustc/ty/subst.rs
@@ -47,7 +47,7 @@ impl<'tcx> From<Ty<'tcx>> for Kind<'tcx> {
         let ptr = ty as *const _ as usize;
         Kind {
             ptr: unsafe {
-                NonZero::new(ptr | TYPE_TAG)
+                NonZero::new_unchecked(ptr | TYPE_TAG)
             },
             marker: PhantomData
         }
@@ -62,7 +62,7 @@ impl<'tcx> From<ty::Region<'tcx>> for Kind<'tcx> {
         let ptr = r as *const _ as usize;
         Kind {
             ptr: unsafe {
-                NonZero::new(ptr | REGION_TAG)
+                NonZero::new_unchecked(ptr | REGION_TAG)
             },
             marker: PhantomData
         }
diff --git a/src/librustc_data_structures/array_vec.rs b/src/librustc_data_structures/array_vec.rs
index 078bb801751..de028f61090 100644
--- a/src/librustc_data_structures/array_vec.rs
+++ b/src/librustc_data_structures/array_vec.rs
@@ -146,7 +146,7 @@ impl<A: Array> ArrayVec<A> {
                 tail_start: end,
                 tail_len: len - end,
                 iter: range_slice.iter(),
-                array_vec: Shared::new(self as *mut _),
+                array_vec: Shared::new_unchecked(self as *mut _),
             }
         }
     }
diff --git a/src/librustc_data_structures/obligation_forest/node_index.rs b/src/librustc_data_structures/obligation_forest/node_index.rs
index 023c56ca59b..9fa6045146d 100644
--- a/src/librustc_data_structures/obligation_forest/node_index.rs
+++ b/src/librustc_data_structures/obligation_forest/node_index.rs
@@ -19,7 +19,7 @@ pub struct NodeIndex {
 impl NodeIndex {
     pub fn new(value: usize) -> NodeIndex {
         assert!(value < (u32::MAX as usize));
-        unsafe { NodeIndex { index: NonZero::new((value as u32) + 1) } }
+        unsafe { NodeIndex { index: NonZero::new_unchecked((value as u32) + 1) } }
     }
 
     pub fn get(self) -> usize {
diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs
index d7ed0938e88..63c204fbdcd 100644
--- a/src/librustc_mir/dataflow/move_paths/mod.rs
+++ b/src/librustc_mir/dataflow/move_paths/mod.rs
@@ -42,7 +42,7 @@ pub(crate) mod indexes {
 
             impl Idx for $Index {
                 fn new(idx: usize) -> Self {
-                    unsafe { $Index(NonZero::new(idx + 1)) }
+                    unsafe { $Index(NonZero::new_unchecked(idx + 1)) }
                 }
                 fn index(self) -> usize {
                     self.0.get() - 1
diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs
index 06f4f7643ec..f3aec589e7d 100644
--- a/src/libstd/collections/hash/table.rs
+++ b/src/libstd/collections/hash/table.rs
@@ -44,7 +44,7 @@ impl TaggedHashUintPtr {
     #[inline]
     unsafe fn new(ptr: *mut HashUint) -> Self {
         debug_assert!(ptr as usize & 1 == 0 || ptr as usize == EMPTY as usize);
-        TaggedHashUintPtr(Unique::new(ptr))
+        TaggedHashUintPtr(Unique::new_unchecked(ptr))
     }
 
     #[inline]
@@ -56,7 +56,7 @@ impl TaggedHashUintPtr {
             } else {
                 usize_ptr &= !1;
             }
-            self.0 = Unique::new(usize_ptr as *mut HashUint)
+            self.0 = Unique::new_unchecked(usize_ptr as *mut HashUint)
         }
     }
 
@@ -877,7 +877,7 @@ impl<K, V> RawTable<K, V> {
                 elems_left: elems_left,
                 marker: marker::PhantomData,
             },
-            table: unsafe { Shared::new(self) },
+            table: unsafe { Shared::new_unchecked(self) },
             marker: marker::PhantomData,
         }
     }
diff --git a/src/test/run-pass/issue-23433.rs b/src/test/run-pass/issue-23433.rs
index 82f80586b9f..6c4c425cb8e 100644
--- a/src/test/run-pass/issue-23433.rs
+++ b/src/test/run-pass/issue-23433.rs
@@ -16,7 +16,7 @@ use std::ptr::Unique;
 
 fn main() {
     let mut a = [0u8; 5];
-    let b: Option<Unique<[u8]>> = unsafe { Some(Unique::new(&mut a)) };
+    let b: Option<Unique<[u8]>> = unsafe { Some(Unique::new_unchecked(&mut a)) };
     match b {
         Some(_) => println!("Got `Some`"),
         None => panic!("Unexpected `None`"),
diff --git a/src/test/ui/print_type_sizes/nullable.rs b/src/test/ui/print_type_sizes/nullable.rs
index f7fdcac81da..df5c53daf7e 100644
--- a/src/test/ui/print_type_sizes/nullable.rs
+++ b/src/test/ui/print_type_sizes/nullable.rs
@@ -57,7 +57,7 @@ pub struct NestedNonZero<T: Zeroable> {
 impl<T: Zeroable+Default> Default for NestedNonZero<T> {
     fn default() -> Self {
         unsafe {
-            NestedNonZero { pre: 0, val: NonZero::new(Default::default()), post: 0 }
+            NestedNonZero { pre: 0, val: NonZero::new_unchecked(Default::default()), post: 0 }
         }
     }
 }