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
|
@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 |
…rfonthey Stabilize `mem::conjure_zst` Tracking issue: rust-lang#95383 --- Stabilized API: ```rust 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`](https://doc.rust-lang.org/nightly/std/any/fn.type_name.html) is currently [unstable in const](rust-lang#63084). --- Implementation history: * rust-lang#95385 (attempted to add the API without an ACP, and then the PR was closed) * rust-lang/libs-team#292 (The ACP. It has a lot of additional context and discussion, including the explanation of why this is needed) * rust-lang#146479 (the actual implementation) * rust-lang#153073 (changes the panic message) * rust-lang#155840 (internal implementation change)
Rollup merge of #161710 - theemathas:stab-conjure-zst, r=clarfonthey Stabilize `mem::conjure_zst` Tracking issue: #95383 --- Stabilized API: ```rust 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`](https://doc.rust-lang.org/nightly/std/any/fn.type_name.html) is currently [unstable in const](#63084). --- Implementation history: * #95385 (attempted to add the API without an ACP, and then the PR was closed) * rust-lang/libs-team#292 (The ACP. It has a lot of additional context and discussion, including the explanation of why this is needed) * #146479 (the actual implementation) * #153073 (changes the panic message) * #155840 (internal implementation change)
Stabilize `mem::conjure_zst` Tracking issue: rust-lang/rust#95383 --- Stabilized API: ```rust 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`](https://doc.rust-lang.org/nightly/std/any/fn.type_name.html) is currently [unstable in const](rust-lang/rust#63084). --- Implementation history: * rust-lang/rust#95385 (attempted to add the API without an ACP, and then the PR was closed) * rust-lang/libs-team#292 (The ACP. It has a lot of additional context and discussion, including the explanation of why this is needed) * rust-lang/rust#146479 (the actual implementation) * rust-lang/rust#153073 (changes the panic message) * rust-lang/rust#155840 (internal implementation change)
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.)