Skip to content

Confusing Error Utilizing let_chains #90722

Closed
@HTGAzureX1212

Description

@HTGAzureX1212

rustc --version --verbose:

rustc 1.58.0-nightly (495322d77 2021-11-08)
binary: rustc
commit-hash: 495322d776fd6f679cd8cd4ca02b8fa834da654b
commit-date: 2021-11-08
host: x86_64-pc-windows-msvc
release: 1.58.0-nightly
LLVM version: 13.0.0

Code:

// #![feature(let_chains)]

if let SelectScope::Fields(fields) = self.scope && self.constraint.is_none() {
    /* snip */
    if let Some(field) = fields
        .iter()
        .find(|name| {
            table_columns_iter
                .find(|ref_multi| ref_multi.key() == *name)
                .is_none()
        })
    /* snip */

Error Output:

error[E0381]: borrow of possibly-uninitialized variable: `fields`
   --> src\ql\select.rs:108:34
    |
108 |               if let Some(field) = fields
    |  __________________________________^
109 | |                 .iter()
    | |_______________________^ use of possibly-uninitialized `fields`

For more information about this error, try `rustc --explain E0381`.

Is it me, or is the error being a bit confusing, that shouldn't fields be already initialized due to the if let, being only assigned to if the value is indeed SelectScope::Fields(<field vector>) (or am I misunderstanding things)? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.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