-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add mem::conjure_zst
for creating ZSTs out of nothing
#95385
base: master
Are you sure you want to change the base?
Conversation
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
This adds a new
unsafe fn
tomem
which can create instances of ZSTs (and only ZSTs).I think this is valuable for a few reasons:
zeroed()
oruninitialized()
ornew_uninit().assume_init()
ortransmute_copy
or ... 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>() == 0
runtime 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.)