@@ -2491,20 +2491,17 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
2491
2491
Expectation :: rvalue_hint ( fcx. tcx ( ) , ty)
2492
2492
} ) ;
2493
2493
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) ) ;
2508
2505
}
2509
2506
2510
2507
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>,
2626
2623
fn check_expr_eq_type < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
2627
2624
expr : & ' tcx hir:: Expr ,
2628
2625
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) ) ;
2632
2628
}
2633
2629
2634
2630
pub fn check_expr_has_type < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
2635
2631
expr : & ' tcx hir:: Expr ,
2636
2632
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) ) ;
2640
2635
}
2641
2636
2642
2637
fn check_expr_coercable_to_type < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
2643
2638
expr : & ' tcx hir:: Expr ,
2644
2639
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) ;
2648
2642
}
2649
2643
2650
2644
fn check_expr_with_hint < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > , expr : & ' tcx hir:: Expr ,
2651
2645
expected : Ty < ' tcx > ) {
2652
- check_expr_with_unifier (
2653
- fcx, expr, ExpectHasType ( expected) , NoPreference ,
2654
- || ( ) )
2646
+ check_expr_with_expectation ( fcx, expr, ExpectHasType ( expected) )
2655
2647
}
2656
2648
2657
2649
fn check_expr_with_expectation < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
2658
2650
expr : & ' tcx hir:: Expr ,
2659
2651
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 )
2671
2653
}
2672
2654
2673
2655
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 )
2675
2657
}
2676
2658
2677
2659
fn check_expr_with_lvalue_pref < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > , expr : & ' tcx hir:: Expr ,
2678
2660
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)
2680
2662
}
2681
2663
2682
2664
// 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>,
2778
2760
/// Note that inspecting a type's structure *directly* may expose the fact
2779
2761
/// that there are actually multiple representations for `TyError`, so avoid
2780
2762
/// 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 ) {
2788
2767
debug ! ( ">> typechecking: expr={:?} expected={:?}" ,
2789
2768
expr, expected) ;
2790
2769
@@ -3662,8 +3641,6 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
3662
3641
debug ! ( "... {:?}, expected is {:?}" ,
3663
3642
fcx. expr_ty( expr) ,
3664
3643
expected) ;
3665
-
3666
- unifier ( ) ;
3667
3644
}
3668
3645
3669
3646
pub fn resolve_ty_and_def_ufcs < ' a , ' b , ' tcx > ( fcx : & FnCtxt < ' b , ' tcx > ,
0 commit comments