Stabilize mem::conjure_zst - #161710
Conversation
Tracking issue: rust-lang#95383
|
cc @rust-lang/wg-const-eval |
|
r? @clarfonthey rustbot has assigned @clarfonthey. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| /// - You must use the value only in ways which do not violate any *safety* | ||
| /// invariants of the type. |
There was a problem hiding this comment.
This might be the first time we use the term "safety invariant" in the docs? Elsewhere we describe the concept rather than naming it, e.g. https://doc.rust-lang.org/nightly/std/mem/union.MaybeUninit.html#method.assume_init :
On top of that, remember that most types have additional invariants beyond merely being considered initialized at the type level. For example, a 1-initialized Vec is considered initialized (under the current implementation; this does not constitute a stable guarantee) because the only requirement the compiler knows about it is that the data pointer must be non-null. Creating such a Vec does not cause immediate undefined behavior, but will cause undefined behavior with most safe operations (including dropping it).
|
@rfcbot fcp merge libs |
|
@nia-e has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Tracking issue: #95383
Stabilized API:
The notable thing about this implementation is that if this function is called at run time (as opposed to in consteval), then the function will panic at run time (as opposed to at compile time) if
Tis not a ZST.If the function panics in consteval, the panic message is a fixed literal string. If the function panics at run time, the panic message includes the
type_nameofT. Note thattype_nameis currently unstable in const.Implementation history:
mem::conjure_zstfor creating ZSTs out of nothing #95385 (attempted to add the API without an ACP, and then the PR was closed)unsafe fnfor creating a ZST libs-team#292 (The ACP. It has a lot of additional context and discussion, including the explanation of why this is needed)T::IS_ZSTover manual check #155840 (internal implementation change)