Tracking issue for release notes of #161710: Stabilize `mem::conjure_zst`
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- rust
- Domain
- documentation, release
Research direction
Start with the provided Release notes text, then read the Forge release-notes chapter and recent previous releases for category and wording examples. Confirm the entry for std::mem::conjure_zst is concise and correctly categorized, add compatibility or stabilization headers only if applicable, and leave the blog section empty unless the change is notable.
Written by the indexing model from the issue text.
Description
This issue tracks the release notes text for #161710.
cc @theemathas, @clarfonthey -- original issue/PR authors and assignees for drafting text
See the forge.rust-lang.org chapter about release notes for an overview of how the release team makes use of these tracking issues.
Release notes text
This section should be edited to specify the correct category(s) for the change, with succinct description(s) of what changed. Some things worth considering:
- Does this need an additional compat notes section?
- Was this a libs stabilization that should have additional headers to list new APIs under
Stabilized APIsandConst Stabilized APIs?
# Stabilized APIs
- [`std::mem::conjure_zst`](https://doc.rust-lang.org/std/mem/fn.conjure_zst.html)
[!TIP]
Use the previous releases for inspiration on how to write the release notes text and which categories to pick.
Release blog section
If this change is notable enough for inclusion in the blog post then this section should be edited to contain a draft for the blog post. Otherwise leave it empty.
# Conjuring zero-sized types
As Rust's [unsafe code guidelines](https://github.com/rust-lang/unsafe-code-guidelines) are still being decided, it became clear that it would be very useful to decide what exactly it means to create zero-sized types in an unsafe way, and what we should recommend for people to do this.
This question is answered in Rust 1.100 with a single function: [`std::mem::conjure_zst`](https://doc.rust-lang.org/stable/std/mem/fn.conjure_zst.html).
Instead of transmuting `()`, `MaybeUninit::uninit().assume_init()`, or various other incantations, this is the dedicated way to create a value of a zero-sized type when you know that doing so is safe to do. If the type has no size, we know exactly what value it must be: nothing.
Of course, APIs often rely on the inability to construct such types for safety, and that's why this function is unsafe. For example, take this contrived example:
```rust
use std::cell::Cell;
use std::sync::atomic::{AtomicUsize, Ordering};
// look, I said the example was contrived, okay?
static HANDLE: Cell<*const AtomicUsize> = std::ptr::null();
static COUNTER: AtomicUsize = AtomicUsize::new(0);
// outside this module, you can't make your own `Handle`
pub struct Handle(());
impl Handle {
pub fn setup() -> Handle {
HANDLE.set(&raw const COUNTER);
Handle(())
}
pub fn count(&self) -> usize {
// SAFETY: We initialized `HANDLE` in the constructor, so, this is a valid pointer.
let atomic = unsafe { &*HANDLE.get() };
atomic.fetch_add(1, Ordering::Relaxed)
}
}
```
Here, the module exploits the fact that `Handle` *cannot be used* without first setting up `HANDLE`, to make the `count` function safe. If we could just `conjure_zst::<Handle>()` in safe code, this is no longer sound, which is why it's unsafe to call `conjure_zst`.
[!NOTE]
If a blog post section is required the
release-blog-postlabel should be added (@rustbot label +release-blog-post) to this issue as otherwise it may be missed by the release team.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 558
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-lang/rust
-
C-bug L-linker_messages needs-triage O-emscripten P-low T-compiler
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
rust-lang/rust#163441 · 1 comment ·
Maintainers usually reply within 1 day
-
relnotes relnotes-tracking-issue T-bootstrap T-libs
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
needs-triage relnotes relnotes-tracking-issue T-clippy T-libs
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
A-process needs-triage O-windows relnotes relnotes-tracking-issue T-libs
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
needs-triage relnotes relnotes-tracking-issue T-compiler
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
vercel-labs/agent-browser#2017 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
tursodatabase/turso#9405 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
PolyMeilex/Neothesia#447 ·
Maintainers usually reply within 1 day
-
backend::vllm diffusion multimodal
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
trezor/trezor-firmware#7985 ·
Maintainers usually reply within 2 days