Skip to content

Commit caa477c

Browse files
committed
feat(allocator/vec): remove ManuallyDrop wrapper (#9742)
Partially revert #6623, It still keeps the check for non-`drop` element of `Vec`
1 parent 65643bc commit caa477c

File tree

1 file changed

+7
-12
lines changed
  • crates/oxc_allocator/src

1 file changed

+7
-12
lines changed

crates/oxc_allocator/src/vec.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::{
99
self,
1010
fmt::{self, Debug},
1111
hash::{Hash, Hasher},
12-
mem::ManuallyDrop,
1312
ops,
1413
slice::SliceIndex,
1514
};
@@ -35,7 +34,7 @@ use crate::{Allocator, Box};
3534
/// Static checks make this impossible to do. [`Vec::new_in`] and all other methods which create
3635
/// a [`Vec`] will refuse to compile if called with a [`Drop`] type.
3736
#[derive(PartialEq, Eq)]
38-
pub struct Vec<'alloc, T>(pub(crate) ManuallyDrop<InnerVec<'alloc, T>>);
37+
pub struct Vec<'alloc, T>(InnerVec<'alloc, T>);
3938

4039
/// SAFETY: Not actually safe, but for enabling `Send` for downstream crates.
4140
unsafe impl<T> Send for Vec<'_, T> {}
@@ -65,7 +64,7 @@ impl<'alloc, T> Vec<'alloc, T> {
6564
pub fn new_in(allocator: &'alloc Allocator) -> Self {
6665
const { Self::ASSERT_T_IS_NOT_DROP };
6766

68-
Self(ManuallyDrop::new(InnerVec::new_in(allocator.bump())))
67+
Self(InnerVec::new_in(allocator.bump()))
6968
}
7069

7170
/// Constructs a new, empty `Vec<T>` with at least the specified capacity
@@ -118,7 +117,7 @@ impl<'alloc, T> Vec<'alloc, T> {
118117
pub fn with_capacity_in(capacity: usize, allocator: &'alloc Allocator) -> Self {
119118
const { Self::ASSERT_T_IS_NOT_DROP };
120119

121-
Self(ManuallyDrop::new(InnerVec::with_capacity_in(capacity, allocator.bump())))
120+
Self(InnerVec::with_capacity_in(capacity, allocator.bump()))
122121
}
123122

124123
/// Create a new [`Vec`] whose elements are taken from an iterator and
@@ -132,7 +131,7 @@ impl<'alloc, T> Vec<'alloc, T> {
132131
let iter = iter.into_iter();
133132
let hint = iter.size_hint();
134133
let capacity = hint.1.unwrap_or(hint.0);
135-
let mut vec = ManuallyDrop::new(InnerVec::with_capacity_in(capacity, allocator.bump()));
134+
let mut vec = InnerVec::with_capacity_in(capacity, allocator.bump());
136135
vec.extend(iter);
137136
Self(vec)
138137
}
@@ -163,7 +162,7 @@ impl<'alloc, T> Vec<'alloc, T> {
163162
// `len` and `capacity` are both `N`.
164163
// Allocated size cannot be larger than `isize::MAX`, or `Box::new_in` would have failed.
165164
let vec = unsafe { InnerVec::from_raw_parts_in(ptr, N, N, allocator.bump()) };
166-
Self(ManuallyDrop::new(vec))
165+
Self(vec)
167166
}
168167
}
169168

@@ -189,10 +188,7 @@ impl<'alloc, T> IntoIterator for Vec<'alloc, T> {
189188

190189
#[inline(always)]
191190
fn into_iter(self) -> Self::IntoIter {
192-
let inner = ManuallyDrop::into_inner(self.0);
193-
// TODO: `allocator_api2::vec::Vec::IntoIter` is `Drop`.
194-
// Wrap it in `ManuallyDrop` to prevent that.
195-
inner.into_iter()
191+
self.0.into_iter()
196192
}
197193
}
198194

@@ -261,8 +257,7 @@ impl<T: Hash> Hash for Vec<'_, T> {
261257

262258
impl<T: Debug> Debug for Vec<'_, T> {
263259
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
264-
let inner = &*self.0;
265-
f.debug_tuple("Vec").field(inner).finish()
260+
f.debug_tuple("Vec").field(&self.0).finish()
266261
}
267262
}
268263

0 commit comments

Comments
 (0)