Clarify deliberate panic paths
This commit is contained in:
+15
-9
@@ -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() }
|
||||
|
||||
Reference in New Issue
Block a user