about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2017-12-22 19:24:07 +0100
committerSimon Sapin <simon.sapin@exyr.org>2018-01-20 11:09:22 +0100
commita2f878a084c8000dd1dcacc02cae5ebc5603fe72 (patch)
tree1a22eca86173c7e603fe758e41ea7dd8b8bdeecc /src/liballoc
parentfb03a49c2501c52401b3c987fd455818de1736f2 (diff)
downloadrust-a2f878a084c8000dd1dcacc02cae5ebc5603fe72.tar.gz
rust-a2f878a084c8000dd1dcacc02cae5ebc5603fe72.zip
Replace Box::{from,into}_unique with {from,into}_nonnull_raw
Thew `_raw` prefix is included because the fact that `Box`’s ownership
semantics are "dissolved" or recreated seem more important than the exact
parameter type or return type.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/arc.rs6
-rw-r--r--src/liballoc/boxed.rs47
-rw-r--r--src/liballoc/linked_list.rs8
-rw-r--r--src/liballoc/rc.rs8
4 files changed, 38 insertions, 31 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs
index 49a6220d591..e490f67dd92 100644
--- a/src/liballoc/arc.rs
+++ b/src/liballoc/arc.rs
@@ -286,7 +286,7 @@ impl<T> Arc<T> {
             weak: atomic::AtomicUsize::new(1),
             data,
         };
-        Arc { ptr: NonNull::from(Box::into_unique(x)), phantom: PhantomData }
+        Arc { ptr: Box::into_nonnull_raw(x), phantom: PhantomData }
     }
 
     /// Returns the contained value, if the `Arc` has exactly one strong reference.
@@ -991,11 +991,11 @@ impl<T> Weak<T> {
     pub fn new() -> Weak<T> {
         unsafe {
             Weak {
-                ptr: NonNull::from(Box::into_unique(box ArcInner {
+                ptr: Box::into_nonnull_raw(box ArcInner {
                     strong: atomic::AtomicUsize::new(0),
                     weak: atomic::AtomicUsize::new(1),
                     data: uninitialized(),
-                })),
+                }),
             }
         }
     }
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index 6f125cdba81..994466e2249 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -68,7 +68,7 @@ use core::marker::{self, Unsize};
 use core::mem;
 use core::ops::{CoerceUnsized, Deref, DerefMut, Generator, GeneratorState};
 use core::ops::{BoxPlace, Boxed, InPlace, Place, Placer};
-use core::ptr::{self, Unique};
+use core::ptr::{self, NonNull, Unique};
 use core::convert::From;
 use str::from_boxed_utf8_unchecked;
 
@@ -269,38 +269,38 @@ impl<T: ?Sized> Box<T> {
     #[stable(feature = "box_raw", since = "1.4.0")]
     #[inline]
     pub unsafe fn from_raw(raw: *mut T) -> Self {
-        Box::from_unique(Unique::new_unchecked(raw))
+        Box(Unique::new_unchecked(raw))
     }
 
-    /// Constructs a `Box` from a `Unique<T>` pointer.
+    /// Constructs a `Box` from a `NonNull<T>` pointer.
     ///
     /// After calling this function, the memory is owned by a `Box` and `T` can
     /// then be destroyed and released upon drop.
     ///
     /// # Safety
     ///
-    /// A `Unique<T>` can be safely created via [`Unique::new`] and thus doesn't
+    /// A `NonNull<T>` can be safely created via [`NonNull::new`] and thus doesn't
     /// necessarily own the data pointed to nor is the data guaranteed to live
     /// as long as the pointer.
     ///
-    /// [`Unique::new`]: ../../core/ptr/struct.Unique.html#method.new
+    /// [`NonNull::new`]: ../../core/ptr/struct.NonNull.html#method.new
     ///
     /// # Examples
     ///
     /// ```
-    /// #![feature(unique)]
+    /// #![feature(nonnull)]
     ///
     /// fn main() {
     ///     let x = Box::new(5);
-    ///     let ptr = Box::into_unique(x);
-    ///     let x = unsafe { Box::from_unique(ptr) };
+    ///     let ptr = Box::into_nonnull_raw(x);
+    ///     let x = unsafe { Box::from_nonnull_raw(ptr) };
     /// }
     /// ```
-    #[unstable(feature = "unique", reason = "needs an RFC to flesh out design",
+    #[unstable(feature = "nonnull", reason = "needs an RFC to flesh out design",
                issue = "27730")]
     #[inline]
-    pub unsafe fn from_unique(u: Unique<T>) -> Self {
-        Box(u)
+    pub unsafe fn from_nonnull_raw(u: NonNull<T>) -> Self {
+        Box(u.into())
     }
 
     /// Consumes the `Box`, returning the wrapped raw pointer.
@@ -326,41 +326,48 @@ impl<T: ?Sized> Box<T> {
     #[stable(feature = "box_raw", since = "1.4.0")]
     #[inline]
     pub fn into_raw(b: Box<T>) -> *mut T {
-        Box::into_unique(b).as_ptr()
+        Box::into_nonnull_raw(b).as_ptr()
     }
 
-    /// Consumes the `Box`, returning the wrapped pointer as `Unique<T>`.
+    /// Consumes the `Box`, returning the wrapped pointer as `NonNull<T>`.
     ///
     /// After calling this function, the caller is responsible for the
     /// memory previously managed by the `Box`. In particular, the
     /// caller should properly destroy `T` and release the memory. The
-    /// proper way to do so is to either convert the `Unique<T>` pointer:
+    /// proper way to do so is to either convert the `NonNull<T>` pointer:
     ///
-    /// - Into a `Box` with the [`Box::from_unique`] function.
+    /// - Into a `Box` with the [`Box::from_nonnull_raw`] function.
     ///
     /// - Into a raw pointer and back into a `Box` with the [`Box::from_raw`]
     ///   function.
     ///
     /// Note: this is an associated function, which means that you have
-    /// to call it as `Box::into_unique(b)` instead of `b.into_unique()`. This
+    /// to call it as `Box::into_nonnull_raw(b)`
+    /// instead of `b.into_nonnull_raw()`. This
     /// is so that there is no conflict with a method on the inner type.
     ///
-    /// [`Box::from_unique`]: struct.Box.html#method.from_unique
+    /// [`Box::from_nonnull_raw`]: struct.Box.html#method.from_nonnull_raw
     /// [`Box::from_raw`]: struct.Box.html#method.from_raw
     ///
     /// # Examples
     ///
     /// ```
-    /// #![feature(unique)]
+    /// #![feature(nonnull)]
     ///
     /// fn main() {
     ///     let x = Box::new(5);
-    ///     let ptr = Box::into_unique(x);
+    ///     let ptr = Box::into_nonnull_raw(x);
     /// }
     /// ```
-    #[unstable(feature = "unique", reason = "needs an RFC to flesh out design",
+    #[unstable(feature = "nonnull", reason = "needs an RFC to flesh out design",
                issue = "27730")]
     #[inline]
+    pub fn into_nonnull_raw(b: Box<T>) -> NonNull<T> {
+        Box::into_unique(b).into()
+    }
+
+    #[unstable(feature = "ptr_internals", issue = "0", reason = "use into_nonnull_raw instead")]
+    #[inline]
     pub fn into_unique(b: Box<T>) -> Unique<T> {
         let unique = b.0;
         mem::forget(b);
diff --git a/src/liballoc/linked_list.rs b/src/liballoc/linked_list.rs
index e6e84101275..4c4a00e53fa 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(NonNull::from(Box::into_unique(node)));
+            let node = Some(Box::into_nonnull_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(NonNull::from(Box::into_unique(node)));
+            let node = Some(Box::into_nonnull_raw(node));
 
             match self.tail {
                 None => self.head = node,
@@ -986,11 +986,11 @@ impl<'a, T> IterMut<'a, T> {
                     Some(prev) => prev,
                 };
 
-                let node = Some(NonNull::from(Box::into_unique(box Node {
+                let node = Some(Box::into_nonnull_raw(box Node {
                     next: Some(head),
                     prev: Some(prev),
                     element,
-                })));
+                }));
 
                 prev.as_mut().next = node;
                 head.as_mut().prev = node;
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index aa7b96139fa..590a6837905 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -311,11 +311,11 @@ 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: NonNull::from(Box::into_unique(box RcBox {
+            ptr: Box::into_nonnull_raw(box RcBox {
                 strong: Cell::new(1),
                 weak: Cell::new(1),
                 value,
-            })),
+            }),
             phantom: PhantomData,
         }
     }
@@ -1190,11 +1190,11 @@ impl<T> Weak<T> {
     pub fn new() -> Weak<T> {
         unsafe {
             Weak {
-                ptr: NonNull::from(Box::into_unique(box RcBox {
+                ptr: Box::into_nonnull_raw(box RcBox {
                     strong: Cell::new(0),
                     weak: Cell::new(1),
                     value: uninitialized(),
-                })),
+                }),
             }
         }
     }