Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #14306 - HKalbasi:master, r=HKalbasi
fix block with no termination in or patterns fix #14298
bors 2023-03-10
parent 8ce5a53 · parent 8593132 · commit 14b9d18
-rw-r--r--crates/hir-ty/src/mir/lower.rs6
-rw-r--r--crates/ide-diagnostics/src/handlers/mutability_errors.rs21
2 files changed, 26 insertions, 1 deletions
diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs
index afa5275ac6..8638e1d920 100644
--- a/crates/hir-ty/src/mir/lower.rs
+++ b/crates/hir-ty/src/mir/lower.rs
@@ -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"),
diff --git a/crates/ide-diagnostics/src/handlers/mutability_errors.rs b/crates/ide-diagnostics/src/handlers/mutability_errors.rs
index 9c79ceba01..f73d1302bf 100644
--- a/crates/ide-diagnostics/src/handlers/mutability_errors.rs
+++ b/crates/ide-diagnostics/src/handlers/mutability_errors.rs
@@ -575,6 +575,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
check_diagnostics(