Feature gate: #![feature(mem_conjure_zst)]
This is a tracking issue for the mem::conjure_zst::<T>() function.
There are a variety of possible ways one can do this without this function, but it provides two advantages:
-
It makes it clearer to the reader what's happening and keeps the code author from needing to decide between zeroed() or uninitialized() or MaybeUninit::new_uninit().assume_init() in situations like
|
// Make up a value of this ZST. |
|
Some(unsafe { mem::zeroed() }) |
-
It provides a convenient place to talk about why it's not just safe to do this in all cases.
Public API
// core::mem
pub const unsafe fn conjure_zst<T>() -> T;
Steps / History
Unresolved Questions
Feature gate:
#![feature(mem_conjure_zst)]This is a tracking issue for the
mem::conjure_zst::<T>()function.There are a variety of possible ways one can do this without this function, but it provides two advantages:
It makes it clearer to the reader what's happening and keeps the code author from needing to decide between
zeroed()oruninitialized()orMaybeUninit::new_uninit().assume_init()in situations likerust/library/alloc/src/vec/into_iter.rs
Lines 149 to 150 in ab0c2e1
It provides a convenient place to talk about why it's not just safe to do this in all cases.
Public API
Steps / History
unsafe fnfor creating a ZST libs-team#292 (comment)mem::conjure_zstfor creating ZSTs out of nothing #95385Unresolved Questions
*ptr::null::<()>()(see Make deref_nullptr deny by default instead of warn #148122 (comment)), should be changed to call this instead (once it's stablized)?