-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Locals aren't introduced properly in if-let guards on or-patterns #88015
Comments
@rustbot claim I started debugging this. Error is generated by MIR borrow checker. Repro I'm using: #![feature(if_let_guard)]
pub enum Test {
A,
B,
}
pub fn test() -> bool {
match Test::A {
Test::A | Test::B if let x = false =>
x,
_ => true
}
} MIR after promote-consts: (I think this is the MIR used for borrow checking?) MIR
Problematic variable is The problematic path has |
IfLet guards and or patterns seem to be not handled correctly in the pattern match compiler (rustc_mir_build::build::matches). I'm not sure if this is the problem or a symptom, but currently when we split candidates with or patterns into candidates without or patterns we duplicate the |
another strange behaviour happen when mixing #![feature(if_let_guard, let_chains)]
fn main() {
let xs = vec![0i32];
if let Some(val) = xs.iter().next() && let bind_me = 5 {
dbg!(val, bind_me);
}
}
|
Are there any news on this? I've just got bitten by this bug. |
Following up on this: I'd love to see if-let guards stabilized, and this looks like the main blocker for that. If anyone else would like to see if-let guards stabilized as well, fixing this would be a necessary step that would get us much closer. |
@rustbot claim |
Came to the same conclusion as @osa1 solving this requires more than a simple fix since this will involve changing how we build |
This one seems to be fixed now. I bisected the fix to 9ad5d82...5e57faa, I'm guessing #88642 |
I tried this code:
I expected to see this happen: code compiles successfully
Instead, this happened: the compiler complains about
x
being possibly uninitializedThis is because each candidate subpattern introduces a different local for
x
.cc tracking issue #51114.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: