Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing Error Utilizing let_chains #90722

Closed
HTGAzureX1212 opened this issue Nov 9, 2021 · 4 comments
Closed

Confusing Error Utilizing let_chains #90722

HTGAzureX1212 opened this issue Nov 9, 2021 · 4 comments
Labels
C-bug Category: This is a bug. F-let_chains `#![feature(let_chains)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@HTGAzureX1212
Copy link
Contributor

HTGAzureX1212 commented Nov 9, 2021

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.

@jplatte
Copy link
Contributor

jplatte commented Jan 1, 2022

Here's a simplified example (Playground):

#![feature(let_chains)]

fn main() {
    let x = Some(vec!["test"]);
    
    if let Some(v) = x && v.is_empty() {
        println!("x == Some([])");
    }
}

Let's see whether labeling via rustbot works...

@rustbot label: +C-bug +F-let_chains +T-compiler

@rustbot rustbot added C-bug Category: This is a bug. F-let_chains `#![feature(let_chains)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 1, 2022
@Patrick-Poitras
Copy link
Contributor

This is similar to #92145.

@c410-f3r
Copy link
Contributor

This issue can be closed

@HTGAzureX1212
Copy link
Contributor Author

Issue Closed with the merge of #88642.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-let_chains `#![feature(let_chains)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants