Skip to content

Commit

Permalink
Box::into_vec: use Box::into_raw instead of mem::forget
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 27, 2019
1 parent 1a56ec4 commit 645f685
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 645f685

Please sign in to comment.