Skip to content

Commit 14b9d18

Browse files
committed
Auto merge of rust-lang#14306 - HKalbasi:master, r=HKalbasi
fix block with no termination in or patterns fix rust-lang#14298
2 parents 8ce5a53 + 8593132 commit 14b9d18

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

crates/hir-ty/src/mir/lower.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,11 @@ impl MirLowerCtx<'_> {
10391039
}
10401040
}
10411041
}
1042-
(then_target, (!finished).then_some(current))
1042+
if !finished {
1043+
let ce = *current_else.get_or_insert_with(|| self.new_basic_block());
1044+
self.set_goto(current, ce);
1045+
}
1046+
(then_target, current_else)
10431047
}
10441048
Pat::Record { .. } => not_supported!("record pattern"),
10451049
Pat::Range { .. } => not_supported!("range pattern"),

crates/ide-diagnostics/src/handlers/mutability_errors.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,27 @@ fn main() {
574574
);
575575
}
576576

577+
#[test]
578+
fn or_pattern_no_terminator() {
579+
check_diagnostics(
580+
r#"
581+
enum Foo {
582+
A, B, C, D
583+
}
584+
585+
use Foo::*;
586+
587+
fn f(inp: (Foo, Foo, Foo, Foo)) {
588+
let ((A, B, _, x) | (B, C | D, x, _)) = inp else {
589+
return;
590+
};
591+
x = B;
592+
//^^^^^ 💡 error: cannot mutate immutable variable `x`
593+
}
594+
"#,
595+
);
596+
}
597+
577598
#[test]
578599
fn respect_allow_unused_mut() {
579600
// FIXME: respect

0 commit comments

Comments
 (0)