Skip to content

Optimization of deinitialization became worse in nightly #149727

@theemathas

Description

@theemathas

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):

demo:  ret

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 

Metadata

Metadata

Assignees

Labels

A-codegenArea: Code generationC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchS-has-bisectionStatus: A bisection has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions