diff options
| -rw-r--r-- | crates/hir-ty/src/mir/lower.rs | 6 | ||||
| -rw-r--r-- | crates/ide-diagnostics/src/handlers/mutability_errors.rs | 21 |
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 afa5275ac6b..8638e1d920e 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 9c79ceba01e..f73d1302bf2 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( |
