Skip to content

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

Closed

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

Activity

  1. added
    C-bugCategory: This is a bug.
    on Dec 4, 2023
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 4, 2023
  3. self-assigned this
    on Dec 4, 2023
  4. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    A-let-chainsArea: let chains (if-let, while-let, ...)
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 4, 2023
  5. added 3 commits that reference this issue on Jan 5, 2024
    a99376b
    29a1770
    958417f
  6. added a commit that references this issue on Jan 5, 2024
    16b7d10
  7. added a commit that references this issue on Jan 11, 2024
    84c4b52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-let-chainsArea: let chains (if-let, while-let, ...)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)]`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