Skip to content

if_let_guard + let_chains: used binding is possibly-uninitialized #118593

Closed
@y21

Description

@y21

I tried this code:

#![feature(if_let_guard, let_chains)]

fn main() {
    let opt = Some(1);
    match 1 {
        1 | 2
            if let Some(x) = opt
                && true =>
        {
            x;
        }
        _ => {}
    }
}

I expected to see this happen: the code compiles.

Instead, this happened: it doesn't compile.

error[E0381]: used binding `x` is possibly-uninitialized
  --> y.rs:10:13
   |
7  |             if let Some(x) = opt
   |                         -
   |                         |
   |                         binding initialized here in some conditions
   |                         binding declared here but left uninitialized
...
10 |             x;
   |             ^ `x` used here but it is possibly-uninitialized

If I remove the && true, it does compile.

Meta

rustc --version --verbose:

rustc 1.76.0-nightly (87e1447aa 2023-11-30)
binary: rustc
commit-hash: 87e1447aadaa2899ff6ccabe1fa669eb50fb60a1
commit-date: 2023-11-30
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.5

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.F-if_let_guard`#![feature(if_let_guard)]`F-let_chains`#![feature(let_chains)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions