Add mem::conjure_zst for creating ZSTs out of nothing#95385
Add mem::conjure_zst for creating ZSTs out of nothing#95385scottmcm wants to merge 1 commit intorust-lang:masterfrom
mem::conjure_zst for creating ZSTs out of nothing#95385Conversation
|
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
c784495 to
80ba6dd
Compare
|
The docs LGTM. Currently the function states " |
|
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 |
|
☔ The latest upstream changes (presumably #93700) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Ping from triage: |
|
I probably need to make an ACP for this now, so I'll just close the PR and decide whether to try again later. |
|
(Picking this back up now that the ACP was approved; will need some corresponding updates.) |
d93599e to
249440a
Compare
This comment has been minimized.
This comment has been minimized.
|
@scottmcm seems like this just needs a |
249440a to
43190ce
Compare
|
@scottmcm This hasn't had activity in a while, and I'd like to pick it up. Are you still working on it? |
|
@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.) |
|
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.)