Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/oxc_allocator/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
fmt::{self, Debug, Formatter},
hash::{Hash, Hasher},
marker::PhantomData,
mem::needs_drop,
ops::{self, Deref},
ptr::{self, NonNull},
};
Expand Down Expand Up @@ -62,6 +63,7 @@ impl<'alloc, T> Box<'alloc, T> {
/// let in_arena: Box<i32> = Box::new_in(5, &arena);
/// ```
pub fn new_in(value: T, allocator: &Allocator) -> Self {
const { assert!(!needs_drop::<T>()) };
Self(NonNull::from(allocator.alloc(value)), PhantomData)
}

Expand Down Expand Up @@ -91,6 +93,7 @@ impl<'alloc, T: ?Sized> Box<'alloc, T> {
/// `ptr` must have been created from a `*mut T` or `&mut T` (not a `*const T` / `&T`).
#[inline]
pub(crate) const unsafe fn from_non_null(ptr: NonNull<T>) -> Self {
const { assert!(!needs_drop::<T>()) };
Self(ptr, PhantomData)
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_allocator/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
self,
fmt::{self, Debug},
hash::{Hash, Hasher},
mem::ManuallyDrop,
mem::{needs_drop, ManuallyDrop},
ops,
ptr::NonNull,
};
Expand Down Expand Up @@ -48,6 +48,7 @@ impl<'alloc, T> Vec<'alloc, T> {
/// ```
#[inline]
pub fn new_in(allocator: &'alloc Allocator) -> Self {
const { assert!(!needs_drop::<T>()) };
Self(ManuallyDrop::new(vec::Vec::new_in(allocator)))
}

Expand Down Expand Up @@ -100,6 +101,7 @@ impl<'alloc, T> Vec<'alloc, T> {
/// ```
#[inline]
pub fn with_capacity_in(capacity: usize, allocator: &'alloc Allocator) -> Self {
const { assert!(!needs_drop::<T>()) };
Self(ManuallyDrop::new(vec::Vec::with_capacity_in(capacity, allocator)))
}

Expand All @@ -109,6 +111,7 @@ impl<'alloc, T> Vec<'alloc, T> {
/// This is behaviorially identical to [`FromIterator::from_iter`].
#[inline]
pub fn from_iter_in<I: IntoIterator<Item = T>>(iter: I, allocator: &'alloc Allocator) -> Self {
const { assert!(!needs_drop::<T>()) };
let iter = iter.into_iter();
let hint = iter.size_hint();
let capacity = hint.1.unwrap_or(hint.0);
Expand Down