Skip to content

Commit d2c6bef

Browse files
committed
typeck: Remove the redundant "unifier" from check_expr_with_unifier.
1 parent ad91f19 commit d2c6bef

File tree

1 file changed

+25
-48
lines changed
  • src/librustc_typeck/check

1 file changed

+25
-48
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,20 +2491,17 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
24912491
Expectation::rvalue_hint(fcx.tcx(), ty)
24922492
});
24932493

2494-
check_expr_with_unifier(fcx,
2495-
&arg,
2496-
expected.unwrap_or(ExpectHasType(formal_ty)),
2497-
NoPreference, || {
2498-
// 2. Coerce to the most detailed type that could be coerced
2499-
// to, which is `expected_ty` if `rvalue_hint` returns an
2500-
// `ExprHasType(expected_ty)`, or the `formal_ty` otherwise.
2501-
let coerce_ty = expected.and_then(|e| e.only_has_type(fcx));
2502-
demand::coerce(fcx, arg.span, coerce_ty.unwrap_or(formal_ty), &arg);
2503-
2504-
// 3. Relate the expected type and the formal one,
2505-
// if the expected type was used for the coercion.
2506-
coerce_ty.map(|ty| demand::suptype(fcx, arg.span, formal_ty, ty));
2507-
});
2494+
check_expr_with_expectation(fcx, &arg,
2495+
expected.unwrap_or(ExpectHasType(formal_ty)));
2496+
// 2. Coerce to the most detailed type that could be coerced
2497+
// to, which is `expected_ty` if `rvalue_hint` returns an
2498+
// `ExpectHasType(expected_ty)`, or the `formal_ty` otherwise.
2499+
let coerce_ty = expected.and_then(|e| e.only_has_type(fcx));
2500+
demand::coerce(fcx, arg.span, coerce_ty.unwrap_or(formal_ty), &arg);
2501+
2502+
// 3. Relate the expected type and the formal one,
2503+
// if the expected type was used for the coercion.
2504+
coerce_ty.map(|ty| demand::suptype(fcx, arg.span, formal_ty, ty));
25082505
}
25092506

25102507
if let Some(&arg_ty) = fcx.inh.tables.borrow().node_types.get(&arg.id) {
@@ -2626,57 +2623,42 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
26262623
fn check_expr_eq_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
26272624
expr: &'tcx hir::Expr,
26282625
expected: Ty<'tcx>) {
2629-
check_expr_with_unifier(
2630-
fcx, expr, ExpectHasType(expected), NoPreference,
2631-
|| demand::eqtype(fcx, expr.span, expected, fcx.expr_ty(expr)));
2626+
check_expr_with_hint(fcx, expr, expected);
2627+
demand::eqtype(fcx, expr.span, expected, fcx.expr_ty(expr));
26322628
}
26332629

26342630
pub fn check_expr_has_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
26352631
expr: &'tcx hir::Expr,
26362632
expected: Ty<'tcx>) {
2637-
check_expr_with_unifier(
2638-
fcx, expr, ExpectHasType(expected), NoPreference,
2639-
|| demand::suptype(fcx, expr.span, expected, fcx.expr_ty(expr)));
2633+
check_expr_with_hint(fcx, expr, expected);
2634+
demand::suptype(fcx, expr.span, expected, fcx.expr_ty(expr));
26402635
}
26412636

26422637
fn check_expr_coercable_to_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
26432638
expr: &'tcx hir::Expr,
26442639
expected: Ty<'tcx>) {
2645-
check_expr_with_unifier(
2646-
fcx, expr, ExpectHasType(expected), NoPreference,
2647-
|| demand::coerce(fcx, expr.span, expected, expr));
2640+
check_expr_with_hint(fcx, expr, expected);
2641+
demand::coerce(fcx, expr.span, expected, expr);
26482642
}
26492643

26502644
fn check_expr_with_hint<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, expr: &'tcx hir::Expr,
26512645
expected: Ty<'tcx>) {
2652-
check_expr_with_unifier(
2653-
fcx, expr, ExpectHasType(expected), NoPreference,
2654-
|| ())
2646+
check_expr_with_expectation(fcx, expr, ExpectHasType(expected))
26552647
}
26562648

26572649
fn check_expr_with_expectation<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
26582650
expr: &'tcx hir::Expr,
26592651
expected: Expectation<'tcx>) {
2660-
check_expr_with_unifier(
2661-
fcx, expr, expected, NoPreference,
2662-
|| ())
2663-
}
2664-
2665-
fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
2666-
expr: &'tcx hir::Expr,
2667-
expected: Expectation<'tcx>,
2668-
lvalue_pref: LvaluePreference)
2669-
{
2670-
check_expr_with_unifier(fcx, expr, expected, lvalue_pref, || ())
2652+
check_expr_with_expectation_and_lvalue_pref(fcx, expr, expected, NoPreference)
26712653
}
26722654

26732655
fn check_expr<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, expr: &'tcx hir::Expr) {
2674-
check_expr_with_unifier(fcx, expr, NoExpectation, NoPreference, || ())
2656+
check_expr_with_expectation(fcx, expr, NoExpectation)
26752657
}
26762658

26772659
fn check_expr_with_lvalue_pref<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, expr: &'tcx hir::Expr,
26782660
lvalue_pref: LvaluePreference) {
2679-
check_expr_with_unifier(fcx, expr, NoExpectation, lvalue_pref, || ())
2661+
check_expr_with_expectation_and_lvalue_pref(fcx, expr, NoExpectation, lvalue_pref)
26802662
}
26812663

26822664
// determine the `self` type, using fresh variables for all variables
@@ -2778,13 +2760,10 @@ fn expected_types_for_fn_args<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
27782760
/// Note that inspecting a type's structure *directly* may expose the fact
27792761
/// that there are actually multiple representations for `TyError`, so avoid
27802762
/// that when err needs to be handled differently.
2781-
fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
2782-
expr: &'tcx hir::Expr,
2783-
expected: Expectation<'tcx>,
2784-
lvalue_pref: LvaluePreference,
2785-
unifier: F) where
2786-
F: FnOnce(),
2787-
{
2763+
fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
2764+
expr: &'tcx hir::Expr,
2765+
expected: Expectation<'tcx>,
2766+
lvalue_pref: LvaluePreference) {
27882767
debug!(">> typechecking: expr={:?} expected={:?}",
27892768
expr, expected);
27902769

@@ -3662,8 +3641,6 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
36623641
debug!("... {:?}, expected is {:?}",
36633642
fcx.expr_ty(expr),
36643643
expected);
3665-
3666-
unifier();
36673644
}
36683645

36693646
pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,

0 commit comments

Comments
 (0)