Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Tracking issue for release notes of #161710: Stabilize `mem::conjure_zst`

Open Beginner friendly
#163,351 0 comments 0 reactions 0 assignees View on GitHub

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

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

release-blog-post relnotes relnotes-tracking-issue T-libs

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 APIs and Const 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-post label 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-lang/rust

All issues in rust-lang/rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.