Uh oh!
There was an error while loading. Please reload this page.
Add mem::conjure_zst for creating ZSTs out of nothing - #95385
Conversation
rust-highfive
commented
Mar 27, 2022
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
RalfJung
commented
Mar 27, 2022
The docs LGTM. Currently the function states " |
Uh oh!
There was an error while loading. Please reload this page.
scottmcm
commented
Apr 2, 2022
One could also think of this method as part of a future set for
as mentioned in https://doc.rust-lang.org/nightly/std/ptr/fn.invalid.html For example, there could be |
bors
commented
Jun 25, 2022
☔ The latest upstream changes (presumably #93700) made this pull request unmergeable. Please resolve the merge conflicts. |
JohnCSimon
commented
Jul 24, 2022
Ping from triage: |
scottmcm
commented
Oct 1, 2022
I probably need to make an ACP for this now, so I'll just close the PR and decide whether to try again later. |
scottmcm
commented
Dec 11, 2024
(Picking this back up now that the ACP was approved; will need some corresponding updates.) |
d93599e to
249440aCompare
This comment has been minimized.
This comment has been minimized.
hkBst
commented
Feb 14, 2025
@scottmcm seems like this just needs a |
249440a to
43190ceComparerust-log-analyzer
commented
Feb 14, 2025
Qelxiros
commented
Sep 11, 2025
@scottmcm This hasn't had activity in a while, and I'd like to pick it up. Are you still working on it? |
scottmcm
commented
Sep 12, 2025
@Qelxiros Sure, if you want to take it and run with it, please do! (Just comment here once you open the new PR so I'll know to close this one.) |
scottmcm
commented
Oct 11, 2025
Obviated by #146479 |
This adds a new
unsafe fntomemwhich can create instances of ZSTs (and only ZSTs).I think this is valuable for a few reasons:
zeroed()oruninitialized()ornew_uninit().assume_init()ortransmute_copyor ... when you're writing code. (See, for example, this PR conversation Add internalcollect_into_array[_unchecked]to remove duplicate code #82098 (comment) )TL/DR: I think this is a useful piece of "good evil".
The PR also uses it in a few places in the library I quickly spotted where we need to create instances after
size_of::<T>() == 0runtime checks, if you'd like to see usage examples.Naming
To conjure is to summon by or as if by invocation or incantation.
Given that we have transmutation already, I thought that conjuration fit well for this operation -- the method is creating it "from nothing", as opposed to the "from something else" of
mem::transmute. (This seems a pretty pervasive use, here's a game example of conjuration to add to the previous book one.)