dyn_vec/src/bad_things.rs

51 lines
1.3 KiB
Rust

// use std::{fmt::Debug, intrinsics::transmute, mem::{transmute_copy, MaybeUninit, ManuallyDrop}, alloc::{dealloc, Layout}, ptr::drop_in_place};
// trait IsSized {
// type SizedRepr;
// fn is_sized() -> bool;
// }
// impl<T: ?Sized> IsSized for T {
// default type SizedRepr = Box<T>;
// default fn is_sized() -> bool {
// false
// }
// }
// impl<T> IsSized for T {
// type SizedRepr = T;
// fn is_sized() -> bool {
// true
// }
// }
// #[repr(transparent)]
// struct Item<T: ?Sized>(<T as IsSized>::SizedRepr);
// impl<T: ?Sized> Item<T> {
// fn from_box(v: Box<T>) -> Self {
// let ret = if T::is_sized() {
// // SAFETY: #[repr(transparent)], and we know its `SizedRepr` is just `T`
// unsafe { (&*v as *const _ as *const Self).read() }
// let ptr = Box::into_raw(v);
// unsafe { dealloc(ptr.cast(), Layout::for_value_raw(ptr)) }
// } else {
// // SAFETY: #[repr(transparent)], and we know its `SizedRepr` is `Box<T>`
// unsafe { (&v as *const _ as *const Self).read() }
// mem::forget(v);
// };
// ret
// }
// }
// #[test]
// pub fn testing() {
// dbg!(usize::is_sized());
// dbg!(<dyn Debug>::is_sized());
// }