Avoid the assertion in erase

This commit is contained in:
John Kåre Alsaker 2023-03-26 11:22:21 +02:00
parent 36b4199a8e
commit 453e919c37
2 changed files with 8 additions and 8 deletions

View File

@ -33,6 +33,7 @@
#![feature(generators)]
#![feature(get_mut_unchecked)]
#![feature(if_let_guard)]
#![feature(inline_const)]
#![feature(iter_from_generator)]
#![feature(local_key_cell_methods)]
#![feature(negative_impls)]

View File

@ -1,5 +1,4 @@
use crate::ty;
use std::intrinsics::type_name;
use std::mem::{size_of, transmute_copy, MaybeUninit};
#[derive(Copy, Clone)]
@ -17,13 +16,13 @@ pub type Erase<T: Copy + EraseType> = Erased<impl Copy>;
#[inline(always)]
pub fn erase<T: EraseType>(src: T) -> Erase<T> {
assert_eq!(
size_of::<T>(),
size_of::<T::Result>(),
"size of {} must match erased type {}",
type_name::<T>(),
type_name::<T::Result>()
);
// Ensure the sizes match
const {
if std::mem::size_of::<T>() != std::mem::size_of::<T::Result>() {
panic!("size of T must match erased type T::Result")
}
};
Erased::<<T as EraseType>::Result> {
// SAFETY: Is it safe to transmute to MaybeUninit for types with the same sizes.
data: unsafe { transmute_copy(&src) },