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

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

Closed
y21 opened this issue Dec 4, 2023 · 0 comments · Fixed by #119554
Closed

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

y21 opened this issue Dec 4, 2023 · 0 comments · Fixed by #119554
Assignees
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-if_let_guard `#![feature(if_let_guard)]` F-let_chains `#![feature(let_chains)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@y21
Copy link
Member

y21 commented Dec 4, 2023

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
@y21 y21 added the C-bug Category: This is a bug. label Dec 4, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 4, 2023
@matthewjasper matthewjasper self-assigned this Dec 4, 2023
@Noratrieb Noratrieb added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. F-let_chains `#![feature(let_chains)]` F-if_let_guard `#![feature(if_let_guard)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 4, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 5, 2024
…tion, r=compiler-errors

Fix scoping for let chains in match guards

If let guards were previously represented as a different type of guard in HIR and THIR. This meant that let chains in match guards were not handled correctly because they were treated exactly like normal guards.

- Remove `hir::Guard` and `thir::Guard`.
- Make the scoping different between normal guards and if let guards also check for let chains.

closes rust-lang#118593
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 5, 2024
…tion, r=compiler-errors

Fix scoping for let chains in match guards

If let guards were previously represented as a different type of guard in HIR and THIR. This meant that let chains in match guards were not handled correctly because they were treated exactly like normal guards.

- Remove `hir::Guard` and `thir::Guard`.
- Make the scoping different between normal guards and if let guards also check for let chains.

closes rust-lang#118593
@bors bors closed this as completed in 958417f Jan 5, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 5, 2024
Rollup merge of rust-lang#119554 - matthewjasper:remove-guard-distinction, r=compiler-errors

Fix scoping for let chains in match guards

If let guards were previously represented as a different type of guard in HIR and THIR. This meant that let chains in match guards were not handled correctly because they were treated exactly like normal guards.

- Remove `hir::Guard` and `thir::Guard`.
- Make the scoping different between normal guards and if let guards also check for let chains.

closes rust-lang#118593
flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 11, 2024
…tion, r=compiler-errors

Fix scoping for let chains in match guards

If let guards were previously represented as a different type of guard in HIR and THIR. This meant that let chains in match guards were not handled correctly because they were treated exactly like normal guards.

- Remove `hir::Guard` and `thir::Guard`.
- Make the scoping different between normal guards and if let guards also check for let chains.

closes rust-lang#118593
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-if_let_guard `#![feature(if_let_guard)]` 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

Successfully merging a pull request may close this issue.

4 participants