Clarify deliberate panic paths

This commit is contained in:
2026-07-31 03:41:08 +02:00
parent 13f713b820
commit 09a7a2595a
+15 -9
View File
@@ -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<T: 'static>(&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<T>(&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::<T>(),
Layout::new::<T>()
)
}
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::<T>(),
Layout::new::<T>()
);
// SAFETY: Ensured by the caller.
unsafe { res.unwrap_unchecked() }