Skip to content

Locals aren't introduced properly in if-let guards on or-patterns #88015

Closed
@LeSeulArtichaut

Description

@LeSeulArtichaut

I tried this code:

#![feature(if_let_guard)]

fn main() {
    match () {
        () | () if let x = 0 => {
            x;
        },
        _ => {}
    };
}

I expected to see this happen: code compiles successfully

Instead, this happened: the compiler complains about x being possibly uninitialized

error[E0381]: use of possibly-uninitialized variable: `x`
 --> src/main.rs:5:34
  |
5 |         () | () if let x = () => x,
  |                                  ^ use of possibly-uninitialized `x`

This is because each candidate subpattern introduces a different local for x.

cc tracking issue #51114.

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (ccffcafd5 2021-08-11)
binary: rustc
commit-hash: ccffcafd55e58f769d4b0efc0064bf65e76998e4
commit-date: 2021-08-11
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1

Metadata

Metadata

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-bugCategory: This is a bug.F-if_let_guard`#![feature(if_let_guard)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions