Skip to content

Commit

Permalink
Auto merge of #15245 - HKalbasi:mir, r=HKalbasi
Browse files Browse the repository at this point in the history
Fix missing terminator in pattern matching of consts

fix #15238
  • Loading branch information
bors committed Jul 9, 2023
2 parents 5f11c9a + 42d35f8 commit ff15634
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/hir-ty/src/mir/lower/pattern_matching.rs
Expand Up @@ -307,6 +307,11 @@ impl MirLowerCtx<'_> {
mode,
)?,
None => {
// The path is not a variant, so it is a const
if mode != MatchingMode::Check {
// A const don't bind anything. Only needs check.
return Ok((current, current_else));
}
let unresolved_name = || MirLowerError::unresolved_path(self.db, p);
let resolver = self.owner.resolver(self.db.upcast());
let pr = resolver
Expand Down Expand Up @@ -362,8 +367,8 @@ impl MirLowerCtx<'_> {
},
Pat::Lit(l) => match &self.body.exprs[*l] {
Expr::Literal(l) => {
let c = self.lower_literal_to_operand(self.infer[pattern].clone(), l)?;
if mode == MatchingMode::Check {
let c = self.lower_literal_to_operand(self.infer[pattern].clone(), l)?;
self.pattern_match_const(current_else, current, c, cond_place, pattern)?
} else {
(current, current_else)
Expand Down
16 changes: 16 additions & 0 deletions crates/ide-diagnostics/src/handlers/mutability_errors.rs
Expand Up @@ -795,6 +795,22 @@ fn main() {
//^^^^^ 💡 warn: variable does not need to be mutable
f(x);
}
"#,
);
check_diagnostics(
r#"
struct Foo(i32);
const X: Foo = Foo(5);
const Y: Foo = Foo(12);
const fn f(mut a: Foo) -> bool {
//^^^^^ 💡 warn: variable does not need to be mutable
match a {
X | Y => true,
_ => false,
}
}
"#,
);
}
Expand Down

0 comments on commit ff15634

Please sign in to comment.