fix block with no termination in or patterns

This commit is contained in:
hkalbasi 2023-03-09 22:30:27 +03:30
parent 8ce5a53934
commit 8593132a43
2 changed files with 26 additions and 1 deletions

View file

@ -1039,7 +1039,11 @@ impl MirLowerCtx<'_> {
}
}
}
(then_target, (!finished).then_some(current))
if !finished {
let ce = *current_else.get_or_insert_with(|| self.new_basic_block());
self.set_goto(current, ce);
}
(then_target, current_else)
}
Pat::Record { .. } => not_supported!("record pattern"),
Pat::Range { .. } => not_supported!("range pattern"),

View file

@ -574,6 +574,27 @@ fn main() {
);
}
#[test]
fn or_pattern_no_terminator() {
check_diagnostics(
r#"
enum Foo {
A, B, C, D
}
use Foo::*;
fn f(inp: (Foo, Foo, Foo, Foo)) {
let ((A, B, _, x) | (B, C | D, x, _)) = inp else {
return;
};
x = B;
//^^^^^ 💡 error: cannot mutate immutable variable `x`
}
"#,
);
}
#[test]
fn respect_allow_unused_mut() {
// FIXME: respect