Skip to content

Commit e7e164e

Browse files
committed
FIX: Use ManuallyDrop instead of forget in data_repr
ManuallyDrop has the benefit that we use it up front, instead of after any "critical" operations.
1 parent ea0b69e commit e7e164e

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

src/data_repr.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
use std::mem;
3+
use std::mem::ManuallyDrop;
34
use std::ptr::NonNull;
45
use std::slice;
56
use crate::extension::nonnull;
@@ -17,22 +18,20 @@ pub struct OwnedRepr<A> {
1718
}
1819

1920
impl<A> OwnedRepr<A> {
20-
pub(crate) fn from(mut v: Vec<A>) -> Self {
21+
pub(crate) fn from(v: Vec<A>) -> Self {
22+
let mut v = ManuallyDrop::new(v);
2123
let len = v.len();
2224
let capacity = v.capacity();
2325
let ptr = nonnull::nonnull_from_vec_data(&mut v);
24-
mem::forget(v);
2526
Self {
2627
ptr,
2728
len,
2829
capacity,
2930
}
3031
}
3132

32-
pub(crate) fn into_vec(mut self) -> Vec<A> {
33-
let v = self.take_as_vec();
34-
mem::forget(self);
35-
v
33+
pub(crate) fn into_vec(self) -> Vec<A> {
34+
ManuallyDrop::new(self).take_as_vec()
3635
}
3736

3837
pub(crate) fn as_slice(&self) -> &[A] {

0 commit comments

Comments
 (0)