Skip to content

Commit ff15634

Browse files
committed
Auto merge of #15245 - HKalbasi:mir, r=HKalbasi
Fix missing terminator in pattern matching of consts fix #15238
2 parents 5f11c9a + 42d35f8 commit ff15634

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ impl MirLowerCtx<'_> {
307307
mode,
308308
)?,
309309
None => {
310+
// The path is not a variant, so it is a const
311+
if mode != MatchingMode::Check {
312+
// A const don't bind anything. Only needs check.
313+
return Ok((current, current_else));
314+
}
310315
let unresolved_name = || MirLowerError::unresolved_path(self.db, p);
311316
let resolver = self.owner.resolver(self.db.upcast());
312317
let pr = resolver
@@ -362,8 +367,8 @@ impl MirLowerCtx<'_> {
362367
},
363368
Pat::Lit(l) => match &self.body.exprs[*l] {
364369
Expr::Literal(l) => {
365-
let c = self.lower_literal_to_operand(self.infer[pattern].clone(), l)?;
366370
if mode == MatchingMode::Check {
371+
let c = self.lower_literal_to_operand(self.infer[pattern].clone(), l)?;
367372
self.pattern_match_const(current_else, current, c, cond_place, pattern)?
368373
} else {
369374
(current, current_else)

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

+16
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,22 @@ fn main() {
795795
//^^^^^ 💡 warn: variable does not need to be mutable
796796
f(x);
797797
}
798+
"#,
799+
);
800+
check_diagnostics(
801+
r#"
802+
struct Foo(i32);
803+
804+
const X: Foo = Foo(5);
805+
const Y: Foo = Foo(12);
806+
807+
const fn f(mut a: Foo) -> bool {
808+
//^^^^^ 💡 warn: variable does not need to be mutable
809+
match a {
810+
X | Y => true,
811+
_ => false,
812+
}
813+
}
798814
"#,
799815
);
800816
}

0 commit comments

Comments
 (0)