mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-02 01:52:51 +00:00
Fix missing terminator in pattern matching of consts
This commit is contained in:
parent
aa52cbf784
commit
42d35f8af9
@ -307,6 +307,11 @@ impl MirLowerCtx<'_> {
|
|||||||
mode,
|
mode,
|
||||||
)?,
|
)?,
|
||||||
None => {
|
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 unresolved_name = || MirLowerError::unresolved_path(self.db, p);
|
||||||
let resolver = self.owner.resolver(self.db.upcast());
|
let resolver = self.owner.resolver(self.db.upcast());
|
||||||
let pr = resolver
|
let pr = resolver
|
||||||
@ -362,8 +367,8 @@ impl MirLowerCtx<'_> {
|
|||||||
},
|
},
|
||||||
Pat::Lit(l) => match &self.body.exprs[*l] {
|
Pat::Lit(l) => match &self.body.exprs[*l] {
|
||||||
Expr::Literal(l) => {
|
Expr::Literal(l) => {
|
||||||
let c = self.lower_literal_to_operand(self.infer[pattern].clone(), l)?;
|
|
||||||
if mode == MatchingMode::Check {
|
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)?
|
self.pattern_match_const(current_else, current, c, cond_place, pattern)?
|
||||||
} else {
|
} else {
|
||||||
(current, current_else)
|
(current, current_else)
|
||||||
|
@ -795,6 +795,22 @@ fn main() {
|
|||||||
//^^^^^ 💡 warn: variable does not need to be mutable
|
//^^^^^ 💡 warn: variable does not need to be mutable
|
||||||
f(x);
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user