Skip to content

Commit

Permalink
Auto merge of #14306 - HKalbasi:master, r=HKalbasi
Browse files Browse the repository at this point in the history
fix block with no termination in or patterns

fix #14298
  • Loading branch information
bors committed Mar 9, 2023
2 parents 8ce5a53 + 8593132 commit 14b9d18
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/hir-ty/src/mir/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
21 changes: 21 additions & 0 deletions crates/ide-diagnostics/src/handlers/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 14b9d18

Please sign in to comment.