Closed
Description
Hi,
Currently if you want a null fat pointer you need to do something like this:
ptr::null_mut::<[u8;0]>() as *mut [u8]
which isn't fun and take a while to find.
I see 2 ways of implementing this in libcore:
1:
pub const fn null_mut_fat<T>() -> *mut [T] {
null_mut::<[T;0]>() as *mut [T]
}
pub const fn null_fat<T>() -> *const [T] {
null::<[T;0]>() as *const [T]
}
- (Which I think is better because it doesn't bloat more functions)
pub fn null<T: ?Sized>() -> *mut T {
unsafe { MaybeUninit::zeroed().assume_init() }
}
The problem is that the second currently isn't possible in a const fn
. it requires making both zeroed()
and assume_init()
const fn
s, which is physically possible (by making ~4-5 functions const fn
, the only problem there is the debug_assert
in write_bytes
)
But I don't know what's the safety consequences of using intrinsics in const fn
.
If it is safe I can start PRing some of these functions to be const fn
.