diff --git a/crates/oxc_allocator/src/boxed.rs b/crates/oxc_allocator/src/boxed.rs index 46f5a753376e3..e83bbc5659c55 100644 --- a/crates/oxc_allocator/src/boxed.rs +++ b/crates/oxc_allocator/src/boxed.rs @@ -7,6 +7,7 @@ use std::{ fmt::{self, Debug, Formatter}, hash::{Hash, Hasher}, marker::PhantomData, + mem::needs_drop, ops::{self, Deref}, ptr::{self, NonNull}, }; @@ -62,6 +63,7 @@ impl<'alloc, T> Box<'alloc, T> { /// let in_arena: Box = Box::new_in(5, &arena); /// ``` pub fn new_in(value: T, allocator: &Allocator) -> Self { + const { assert!(!needs_drop::()) }; Self(NonNull::from(allocator.alloc(value)), PhantomData) } @@ -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) -> Self { + const { assert!(!needs_drop::()) }; Self(ptr, PhantomData) } } diff --git a/crates/oxc_allocator/src/vec.rs b/crates/oxc_allocator/src/vec.rs index 273120f69e66c..d9b521c178b68 100644 --- a/crates/oxc_allocator/src/vec.rs +++ b/crates/oxc_allocator/src/vec.rs @@ -6,7 +6,7 @@ use std::{ self, fmt::{self, Debug}, hash::{Hash, Hasher}, - mem::ManuallyDrop, + mem::{needs_drop, ManuallyDrop}, ops, ptr::NonNull, }; @@ -48,6 +48,7 @@ impl<'alloc, T> Vec<'alloc, T> { /// ``` #[inline] pub fn new_in(allocator: &'alloc Allocator) -> Self { + const { assert!(!needs_drop::()) }; Self(ManuallyDrop::new(vec::Vec::new_in(allocator))) } @@ -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::()) }; Self(ManuallyDrop::new(vec::Vec::with_capacity_in(capacity, allocator))) } @@ -109,6 +111,7 @@ impl<'alloc, T> Vec<'alloc, T> { /// This is behaviorially identical to [`FromIterator::from_iter`]. #[inline] pub fn from_iter_in>(iter: I, allocator: &'alloc Allocator) -> Self { + const { assert!(!needs_drop::()) }; let iter = iter.into_iter(); let hint = iter.size_hint(); let capacity = hint.1.unwrap_or(hint.0);