rust-lang / rust-lang/rust

debug compiled no-op `transmute_copy` not inlined and contains precondition checks

Open
#161,025 4 comments 0 reactions 1 assignee View on GitHub

@saethlin is already working on this.

Since Aug 16, 2026.

C-optimization T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=0c942f34da6a1a7f062435ea8b8e0920

#[unsafe(no_mangle)]
fn foo(x: [u8; 4]) -> u32 { unsafe { core::mem::transmute_copy(&x) } }
#[unsafe(no_mangle)]
fn bar(x: u32) -> u32 { unsafe { core::mem::transmute_copy(&x) } }

I expected to see this happen: Because both types are trivially copyable (same size, same type for the latter) it should compile down to a register move or whatever.

Instead, this happened: It isn't inlined, and there's a precondition check for the size despite the size being statically known.

I will say it's significantly better than what is emitted on 1.97.1.

Meta

rustc --version --verbose:

1.99.0-nightly

(2026-08-12 c98d0cb27cc63afdd626)

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.