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() }