about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorIvan Tham <pickfire@riseup.net>2020-05-31 17:19:06 +0800
committerIvan Tham <pickfire@riseup.net>2020-05-31 17:19:06 +0800
commit71404633e843e0e5a533c677a764c8cb7f2a55fb (patch)
tree2e5bef2a5ed18e25d8fb5a6ab7ca0a238f0dcbf2 /src/liballoc
parent79449986b707c18df92622a53d83eddd6872d8ee (diff)
downloadrust-71404633e843e0e5a533c677a764c8cb7f2a55fb.tar.gz
rust-71404633e843e0e5a533c677a764c8cb7f2a55fb.zip
Merge raw_vec into_box with previous impl<T, Global>
There are two separate `impl<T, Global>` which no special reason, it would be
better to merge both of them.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/raw_vec.rs50
1 files changed, 24 insertions, 26 deletions
diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs
index 56e284a12fa..5b365f0387a 100644
--- a/src/liballoc/raw_vec.rs
+++ b/src/liballoc/raw_vec.rs
@@ -118,6 +118,30 @@ impl<T> RawVec<T, Global> {
             RawVec::from_raw_parts(slice.as_mut_ptr(), slice.len())
         }
     }
+
+    /// Converts the entire buffer into `Box<[MaybeUninit<T>]>` with the specified `len`.
+    ///
+    /// Note that this will correctly reconstitute any `cap` changes
+    /// that may have been performed. (See description of type for details.)
+    ///
+    /// # Safety
+    ///
+    /// * `len` must be greater than or equal to the most recently requested capacity, and
+    /// * `len` must be less than or equal to `self.capacity()`.
+    ///
+    /// Note, that the requested capacity and `self.capacity()` could differ, as
+    /// an allocator could overallocate and return a greater memory block than requested.
+    pub unsafe fn into_box(self, len: usize) -> Box<[MaybeUninit<T>]> {
+        // Sanity-check one half of the safety requirement (we cannot check the other half).
+        debug_assert!(
+            len <= self.capacity(),
+            "`len` must be smaller than or equal to `self.capacity()`"
+        );
+
+        let me = ManuallyDrop::new(self);
+        let slice = slice::from_raw_parts_mut(me.ptr() as *mut MaybeUninit<T>, len);
+        Box::from_raw(slice)
+    }
 }
 
 impl<T, A: AllocRef> RawVec<T, A> {
@@ -520,32 +544,6 @@ where
     Ok(memory)
 }
 
-impl<T> RawVec<T, Global> {
-    /// Converts the entire buffer into `Box<[MaybeUninit<T>]>` with the specified `len`.
-    ///
-    /// Note that this will correctly reconstitute any `cap` changes
-    /// that may have been performed. (See description of type for details.)
-    ///
-    /// # Safety
-    ///
-    /// * `len` must be greater than or equal to the most recently requested capacity, and
-    /// * `len` must be less than or equal to `self.capacity()`.
-    ///
-    /// Note, that the requested capacity and `self.capacity()` could differ, as
-    /// an allocator could overallocate and return a greater memory block than requested.
-    pub unsafe fn into_box(self, len: usize) -> Box<[MaybeUninit<T>]> {
-        // Sanity-check one half of the safety requirement (we cannot check the other half).
-        debug_assert!(
-            len <= self.capacity(),
-            "`len` must be smaller than or equal to `self.capacity()`"
-        );
-
-        let me = ManuallyDrop::new(self);
-        let slice = slice::from_raw_parts_mut(me.ptr() as *mut MaybeUninit<T>, len);
-        Box::from_raw(slice)
-    }
-}
-
 unsafe impl<#[may_dangle] T, A: AllocRef> Drop for RawVec<T, A> {
     /// Frees the memory owned by the `RawVec` *without* trying to drop its contents.
     fn drop(&mut self) {