debug compiled no-op `transmute_copy` not inlined and contains precondition checks
Open
@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:
#[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
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.
Assessment
This issue has not been assessed yet.