Auto merge of #14306 - HKalbasi:master, r=HKalbasi

fix block with no termination in or patterns

fix #14298
This commit is contained in:
bors 2023-03-09 19:03:47 +00:00
commit 14b9d182d5
2 changed files with 26 additions and 1 deletions

View File

@ -1039,7 +1039,11 @@ fn pattern_match(
}
}
}
(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