Merge #9886
9886: feat: type inference for if-let guards r=jonas-schievink a=jonas-schievink This turned out fairly simple bors r+ Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
commit
c5ddc35a45
@ -366,13 +366,21 @@ fn infer_expr_inner(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
|
||||
for arm in arms {
|
||||
self.diverges = Diverges::Maybe;
|
||||
let _pat_ty = self.infer_pat(arm.pat, &input_ty, BindingMode::default());
|
||||
if let Some(MatchGuard::If { expr: guard_expr }) = arm.guard {
|
||||
self.infer_expr(
|
||||
guard_expr,
|
||||
&Expectation::has_type(TyKind::Scalar(Scalar::Bool).intern(&Interner)),
|
||||
);
|
||||
match arm.guard {
|
||||
Some(MatchGuard::If { expr: guard_expr }) => {
|
||||
self.infer_expr(
|
||||
guard_expr,
|
||||
&Expectation::has_type(
|
||||
TyKind::Scalar(Scalar::Bool).intern(&Interner),
|
||||
),
|
||||
);
|
||||
}
|
||||
Some(MatchGuard::IfLet { expr, pat }) => {
|
||||
let input_ty = self.infer_expr(expr, &Expectation::none());
|
||||
let _pat_ty = self.infer_pat(pat, &input_ty, BindingMode::default());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
// FIXME: infer `if let` guard
|
||||
|
||||
let arm_ty = self.infer_expr_inner(arm.expr, &expected);
|
||||
all_arms_diverge &= self.diverges;
|
||||
|
@ -916,3 +916,20 @@ fn main() {
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn if_let_guards() {
|
||||
check_types(
|
||||
r#"
|
||||
fn main() {
|
||||
match (0,) {
|
||||
opt if let (x,) = opt => {
|
||||
x;
|
||||
//^ i32
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user