Code
I tried this code (not from real code, but just experimenting):
use std::mem::MaybeUninit;
#[unsafe(no_mangle)]
fn demo(x: &mut MaybeUninit<u32>) -> MaybeUninit<u32> {
*x = MaybeUninit::uninit();
*x
}
In beta, this compiles to (Godbolt):
In nightly, this compiles to (Godbolt):
demo:
mov eax, dword ptr [rdi]
ret
Since we've deinitialized the memory that x points to, returning a copy of that memory should result in returning uninit. The compiler should be free to return whatever garbage data it wants, so just ret is a valid compilation, and is probably the best-performing compilation result.
Version it worked on
It most recently worked on Godbolt full compiler version:
rustc 1.92.0-beta.3 (f3f12444a 2025-11-09)
binary: rustc
commit-hash: f3f12444a017add0468f683f3a10656d29438a05
commit-date: 2025-11-09
host: x86_64-unknown-linux-gnu
release: 1.92.0-beta.3
LLVM version: 21.1.3
Internal compiler ID: beta
Version with regression
Godbolt full compiler version:
rustc 1.93.0-nightly (83e49b75e 2025-12-03)
binary: rustc
commit-hash: 83e49b75e7daf827e4390ae0ccbcb0d0e2c96493
commit-date: 2025-12-03
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5
Internal compiler ID: nightly
Code
I tried this code (not from real code, but just experimenting):
In beta, this compiles to (Godbolt):
In nightly, this compiles to (Godbolt):
Since we've deinitialized the memory that
xpoints to, returning a copy of that memory should result in returning uninit. The compiler should be free to return whatever garbage data it wants, so justretis a valid compilation, and is probably the best-performing compilation result.Version it worked on
It most recently worked on Godbolt full compiler version:
Version with regression
Godbolt full compiler version: