From 09a7a2595af242535982f5472a9788086b38a572 Mon Sep 17 00:00:00 2001 From: soruh Date: Fri, 31 Jul 2026 03:41:08 +0200 Subject: [PATCH] Clarify deliberate panic paths --- src/lib.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2e1e1ae..3ee216f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -170,6 +170,10 @@ impl TypeErasedVec { /// /// # Panics /// Panics if `T` does not have the same `Layout` as the underlying capacity. + #[expect( + clippy::panic, + reason = "this infallible convenience method documents and reports layout mismatch" + )] pub fn as_type(&mut self) -> ContentGuard<'_, T> { let layout = self.layout; self.try_as_type().unwrap_or_else(|| { @@ -213,6 +217,10 @@ impl TypeErasedVec { /// /// # Panics /// Panics if `T` needs drop or does not have the erased allocation's layout. + #[expect( + clippy::panic, + reason = "this infallible convenience method documents and reports layout mismatch" + )] pub fn as_type_scoped(&mut self) -> ContentGuard<'_, T> { let layout = self.layout; self.try_as_type_scoped().unwrap_or_else(|| { @@ -235,15 +243,13 @@ impl TypeErasedVec { let layout = self.layout; let res = self.try_as_type(); - #[cfg(debug_assertions)] - if res.is_none() { - unreachable!( - "Calling `as_type_unchecked` with an incompatible layout is UB! Target type layout must exactly match the erased layout. Capacity is reserved for {:?} but {} has {:?}", - layout, - std::any::type_name::(), - Layout::new::() - ) - } + debug_assert!( + res.is_some(), + "Calling `as_type_unchecked` with an incompatible layout is UB! Target type layout must exactly match the erased layout. Capacity is reserved for {:?} but {} has {:?}", + layout, + std::any::type_name::(), + Layout::new::() + ); // SAFETY: Ensured by the caller. unsafe { res.unwrap_unchecked() }