rust-lang / rust-lang/rust

transmutability: high memory unsage for types containing references

Open
#140,610 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-transmutability I-compilemem T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I am running out of memory when trying to compile the following code:

#![feature(transmutability)]
use std::mem::{Assume, TransmuteFrom};
pub fn is_maybe_transmutable<Src, Dst>()
where
    Dst: TransmuteFrom<Src, { Assume::SAFETY }>
{}

pub union U {
    pub a: &'static u8,
    pub b: &'static u16,
    pub c: &'static u32,
    pub d: &'static u64,
}

fn main() {
    is_maybe_transmutable::<[U; 10], [U; 10]>();
}
Meta

rustc --version --verbose:

rustc 1.88.0-nightly (4824c2bb7 2025-05-02)
binary: rustc
commit-hash: 4824c2bb7445cb2478aab0190c268c939d77a0f6
commit-date: 2025-05-02
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Contributor guide

Open the contributing guide

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.

Research direction

Start by compiling the issue's standalone Rust reproducer with the nightly version shown and observe its memory use. Trace the transmutability evaluation for [U; 10] and reference-containing union fields; done means the example no longer exhausts memory and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.