Skip to content

Commit 645f685

Browse files
committed
Box::into_vec: use Box::into_raw instead of mem::forget
1 parent 1a56ec4 commit 645f685

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/liballoc/slice.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,16 @@ pub use hack::to_vec;
137137
// `core::slice::SliceExt` - we need to supply these functions for the
138138
// `test_permutations` test
139139
mod hack {
140-
use core::mem;
141-
142140
use crate::boxed::Box;
143141
use crate::vec::Vec;
144142
#[cfg(test)]
145143
use crate::string::ToString;
146144

147-
pub fn into_vec<T>(mut b: Box<[T]>) -> Vec<T> {
145+
pub fn into_vec<T>(b: Box<[T]>) -> Vec<T> {
148146
unsafe {
149-
let xs = Vec::from_raw_parts(b.as_mut_ptr(), b.len(), b.len());
150-
mem::forget(b);
147+
let len = b.len();
148+
let b = Box::into_raw(b);
149+
let xs = Vec::from_raw_parts(b as *mut T, len, len);
151150
xs
152151
}
153152
}

0 commit comments

Comments
 (0)