about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-05-30 10:52:55 +0200
committerGitHub <noreply@github.com>2019-05-30 10:52:55 +0200
commit1b66a135402e6ef149941bfcb58aaf55051d30fc (patch)
treec3e810069369587054a090f9dc6c0247eff8eee2 /src/liballoc
parent6351267c1fc78ddfd9119f5378e1f79c734da994 (diff)
parent645f685e1b05f3f62de26ea1579861e83cbd0d74 (diff)
downloadrust-1b66a135402e6ef149941bfcb58aaf55051d30fc.tar.gz
rust-1b66a135402e6ef149941bfcb58aaf55051d30fc.zip
Rollup merge of #61244 - RalfJung:box, r=rkruppe
Box::into_vec: use Box::into_raw instead of mem::forget

`Box::into_raw` does, in one step, turn the `Box` into a raw ptr and avoid deallocation.  Seems cleaner than separating the two.

Also, `mem::forget` gets the `Box` with a `noalias` argument, but it is not actually correct that this is an exclusive pointer. So a stricter version of Stacked Borrows would complain here. (I can't actually make Stacked Borrows that strict yet though due to other issues.)
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/slice.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs
index 8768f1ff081..aeb7f90d3e6 100644
--- a/src/liballoc/slice.rs
+++ b/src/liballoc/slice.rs
@@ -137,17 +137,16 @@ pub use hack::to_vec;
 // `core::slice::SliceExt` - we need to supply these functions for the
 // `test_permutations` test
 mod hack {
-    use core::mem;
-
     use crate::boxed::Box;
     use crate::vec::Vec;
     #[cfg(test)]
     use crate::string::ToString;
 
-    pub fn into_vec<T>(mut b: Box<[T]>) -> Vec<T> {
+    pub fn into_vec<T>(b: Box<[T]>) -> Vec<T> {
         unsafe {
-            let xs = Vec::from_raw_parts(b.as_mut_ptr(), b.len(), b.len());
-            mem::forget(b);
+            let len = b.len();
+            let b = Box::into_raw(b);
+            let xs = Vec::from_raw_parts(b as *mut T, len, len);
             xs
         }
     }