commit
eb47e1e446
10 changed files with 64 additions and 24 deletions
|
|
@ -238,7 +238,8 @@ pub fn check_match<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
expr: &ast::Expr,
|
||||
discrim: &ast::Expr,
|
||||
arms: &[ast::Arm],
|
||||
expected: Expectation<'tcx>) {
|
||||
expected: Expectation<'tcx>,
|
||||
match_src: ast::MatchSource) {
|
||||
let tcx = fcx.ccx.tcx;
|
||||
|
||||
let discrim_ty = fcx.infcx().next_ty_var();
|
||||
|
|
@ -290,12 +291,27 @@ pub fn check_match<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
if ty::type_is_error(result_ty) || ty::type_is_error(bty) {
|
||||
ty::mk_err()
|
||||
} else {
|
||||
let (origin, expected, found) = match match_src {
|
||||
/* if-let construct without an else block */
|
||||
ast::MatchSource::IfLetDesugar { contains_else_clause }
|
||||
if !contains_else_clause => (
|
||||
infer::IfExpressionWithNoElse(expr.span),
|
||||
bty,
|
||||
result_ty,
|
||||
),
|
||||
_ => (
|
||||
infer::MatchExpressionArm(expr.span, arm.body.span),
|
||||
result_ty,
|
||||
bty,
|
||||
),
|
||||
};
|
||||
|
||||
infer::common_supertype(
|
||||
fcx.infcx(),
|
||||
infer::MatchExpressionArm(expr.span, arm.body.span),
|
||||
true, // result_ty is "expected" here
|
||||
result_ty,
|
||||
bty
|
||||
origin,
|
||||
true,
|
||||
expected,
|
||||
found,
|
||||
)
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3919,8 +3919,8 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
fcx.write_nil(id);
|
||||
}
|
||||
}
|
||||
ast::ExprMatch(ref discrim, ref arms, _) => {
|
||||
_match::check_match(fcx, expr, &**discrim, arms.as_slice(), expected);
|
||||
ast::ExprMatch(ref discrim, ref arms, match_src) => {
|
||||
_match::check_match(fcx, expr, &**discrim, arms.as_slice(), expected, match_src);
|
||||
}
|
||||
ast::ExprClosure(_, opt_kind, ref decl, ref body) => {
|
||||
closure::check_expr_closure(fcx, expr, opt_kind, &**decl, &**body, expected);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue