Skip to content

Stabilize mem::conjure_zst - #161710

Open
theemathas wants to merge 1 commit into
rust-lang:mainfrom
theemathas:stab-conjure-zst
Open

Stabilize mem::conjure_zst#161710
theemathas wants to merge 1 commit into
rust-lang:mainfrom
theemathas:stab-conjure-zst

Conversation

@theemathas

@theemathas theemathas commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Tracking issue: #95383


Stabilized API:

pub const unsafe fn conjure_zst<T>() -> T;

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 T is 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_name of T. Note that type_name is currently unstable in const.


Implementation history:

@theemathas theemathas added needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 25, 2026
@rustbot

rustbot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

⚠️ #[rustc_allow_const_fn_unstable] needs careful audit to avoid accidentally exposing unstable
implementation details on stable.

cc @rust-lang/wg-const-eval

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 25, 2026
@rustbot

rustbot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

r? @clarfonthey

rustbot has assigned @clarfonthey.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, clarfonthey, nia-e

@clarfonthey clarfonthey added the I-libs-nominated Nominated for discussion during a libs team meeting. label Aug 25, 2026
Comment on lines 1681 to 1682
/// - You must use the value only in ways which do not violate any *safety*
/// invariants of the type.

@RalfJung RalfJung Aug 25, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

View changes since the review

@nia-e

nia-e commented Aug 25, 2026

Copy link
Copy Markdown
Member

@rfcbot fcp merge libs

@rust-rfcbot

rust-rfcbot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

@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.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. and removed needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. labels Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. I-libs-nominated Nominated for discussion during a libs team meeting. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants