Avoid the assertion in erase
This commit is contained in:
parent
36b4199a8e
commit
453e919c37
2 changed files with 8 additions and 8 deletions
|
@ -33,6 +33,7 @@
|
||||||
#![feature(generators)]
|
#![feature(generators)]
|
||||||
#![feature(get_mut_unchecked)]
|
#![feature(get_mut_unchecked)]
|
||||||
#![feature(if_let_guard)]
|
#![feature(if_let_guard)]
|
||||||
|
#![feature(inline_const)]
|
||||||
#![feature(iter_from_generator)]
|
#![feature(iter_from_generator)]
|
||||||
#![feature(local_key_cell_methods)]
|
#![feature(local_key_cell_methods)]
|
||||||
#![feature(negative_impls)]
|
#![feature(negative_impls)]
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::ty;
|
use crate::ty;
|
||||||
use std::intrinsics::type_name;
|
|
||||||
use std::mem::{size_of, transmute_copy, MaybeUninit};
|
use std::mem::{size_of, transmute_copy, MaybeUninit};
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
|
@ -17,13 +16,13 @@ pub type Erase<T: Copy + EraseType> = Erased<impl Copy>;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn erase<T: EraseType>(src: T) -> Erase<T> {
|
pub fn erase<T: EraseType>(src: T) -> Erase<T> {
|
||||||
assert_eq!(
|
// Ensure the sizes match
|
||||||
size_of::<T>(),
|
const {
|
||||||
size_of::<T::Result>(),
|
if std::mem::size_of::<T>() != std::mem::size_of::<T::Result>() {
|
||||||
"size of {} must match erased type {}",
|
panic!("size of T must match erased type T::Result")
|
||||||
type_name::<T>(),
|
}
|
||||||
type_name::<T::Result>()
|
};
|
||||||
);
|
|
||||||
Erased::<<T as EraseType>::Result> {
|
Erased::<<T as EraseType>::Result> {
|
||||||
// SAFETY: Is it safe to transmute to MaybeUninit for types with the same sizes.
|
// SAFETY: Is it safe to transmute to MaybeUninit for types with the same sizes.
|
||||||
data: unsafe { transmute_copy(&src) },
|
data: unsafe { transmute_copy(&src) },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue