From a8ef989084db0d1a0c9f814ea406d167f4a17062 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 27 Apr 2024 21:08:09 -0500 Subject: [PATCH] cl-structures/stack: only drop if T needs drop --- compiler/cl-structures/src/stack.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/cl-structures/src/stack.rs b/compiler/cl-structures/src/stack.rs index 8e96e87..dceee3e 100644 --- a/compiler/cl-structures/src/stack.rs +++ b/compiler/cl-structures/src/stack.rs @@ -164,7 +164,9 @@ unsafe impl<#[may_dangle] T, const N: usize> Drop for Stack { #[inline] fn drop(&mut self) { // Safety: We have ensured that all elements in the list are - unsafe { core::ptr::drop_in_place(self.as_mut_slice()) }; + if std::mem::needs_drop::() { + unsafe { core::ptr::drop_in_place(self.as_mut_slice()) }; + } } } @@ -617,7 +619,6 @@ mod tests { assert_eq!(std::mem::size_of::(), std::mem::size_of_val(&v)) } #[test] - #[cfg_attr(debug_assertions, ignore = "calls ().drop() usize::MAX times")] fn from_usize_max_zst_array() { let mut v = Stack::from([(); usize::MAX]); assert_eq!(v.len(), usize::MAX);