I tried this code:
fn foo(b: bool) {
let x;
if b {
x = 1;
} else {
println!("{x}");
}
}
I expected to see this happen:
since x is uninitialized.
Instead, this happened:
I would consider it incorrect to call x possibly-uninitialized. The differentiation between uninitialized and possibly-uninitialized appears to be here: conflict_errors.rs:827 where it usually suffices that the variable be initialized somewhere to be consider possibly-uninitialized. Indeed even simpler examples exhibit this issue:
let x;
println!("{x}");
x = 1;
However, we have access to the MaybeInitializedPlaces which seems to provide a more accurate criterion to decide whether the variable is possibly or definitely uninitialized. If it's decided that this change is worth making, I would be able to submit a pull request.
Meta
rustc --version --verbose:
rustc 1.98.0-nightly (14210df0e 2026-05-31)
binary: rustc
commit-hash: 14210df0e27ccd7d9e6a05b8085cbd438e4bbc65
commit-date: 2026-05-31
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.6
Backtrace
As the compiler doesn't crash, nothing extra was shown.
I tried this code:
I expected to see this happen:
since x is uninitialized.
Instead, this happened:
I would consider it incorrect to call
xpossibly-uninitialized. The differentiation between uninitialized and possibly-uninitialized appears to be here: conflict_errors.rs:827 where it usually suffices that the variable be initialized somewhere to be consider possibly-uninitialized. Indeed even simpler examples exhibit this issue:However, we have access to the
MaybeInitializedPlaceswhich seems to provide a more accurate criterion to decide whether the variable is possibly or definitely uninitialized. If it's decided that this change is worth making, I would be able to submit a pull request.Meta
rustc --version --verbose:Backtrace
As the compiler doesn't crash, nothing extra was shown.