@@ -60,28 +60,13 @@ use rustc_trait_selection::traits::ObligationCtxt;
6060use rustc_trait_selection:: traits:: { self , ObligationCauseCode } ;
6161
6262impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
63- fn check_expr_eq_type ( & self , expr : & ' tcx hir:: Expr < ' tcx > , expected : Ty < ' tcx > ) {
64- let ty = self . check_expr_with_hint ( expr, expected) ;
65- self . demand_eqtype ( expr. span , expected, ty) ;
66- }
67-
6863 pub fn check_expr_has_type_or_error (
6964 & self ,
7065 expr : & ' tcx hir:: Expr < ' tcx > ,
71- expected : Ty < ' tcx > ,
72- extend_err : impl FnMut ( & mut Diagnostic ) ,
73- ) -> Ty < ' tcx > {
74- self . check_expr_meets_expectation_or_error ( expr, ExpectHasType ( expected) , extend_err)
75- }
76-
77- fn check_expr_meets_expectation_or_error (
78- & self ,
79- expr : & ' tcx hir:: Expr < ' tcx > ,
80- expected : Expectation < ' tcx > ,
81- mut extend_err : impl FnMut ( & mut Diagnostic ) ,
66+ expected_ty : Ty < ' tcx > ,
67+ extend_err : impl FnOnce ( & mut Diagnostic ) ,
8268 ) -> Ty < ' tcx > {
83- let expected_ty = expected. to_option ( & self ) . unwrap_or ( self . tcx . types . bool ) ;
84- let mut ty = self . check_expr_with_expectation ( expr, expected) ;
69+ let mut ty = self . check_expr_with_expectation ( expr, ExpectHasType ( expected_ty) ) ;
8570
8671 // While we don't allow *arbitrary* coercions here, we *do* allow
8772 // coercions from ! to `expected`.
@@ -341,9 +326,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
341326 }
342327 ExprKind :: Cast ( e, t) => self . check_expr_cast ( e, t, expr) ,
343328 ExprKind :: Type ( e, t) => {
344- let ty = self . to_ty_saving_user_provided_ty ( & t) ;
345- self . check_expr_eq_type ( & e, ty) ;
346- ty
329+ let ascribed_ty = self . to_ty_saving_user_provided_ty ( & t) ;
330+ let ty = self . check_expr_with_hint ( e, ascribed_ty) ;
331+ self . demand_eqtype ( e. span , ascribed_ty, ty) ;
332+ ascribed_ty
347333 }
348334 ExprKind :: If ( cond, then_expr, opt_else_expr) => {
349335 self . check_then_else ( cond, then_expr, opt_else_expr, expr. span , expected)
@@ -666,7 +652,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
666652 coerce. coerce_forced_unit (
667653 self ,
668654 & cause,
669- & mut |mut err| {
655+ |mut err| {
670656 self . suggest_mismatched_types_on_tail (
671657 & mut err, expr, ty, e_ty, target_id,
672658 ) ;
@@ -762,7 +748,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
762748 coercion. coerce_forced_unit (
763749 self ,
764750 & cause,
765- & mut |db| {
751+ |db| {
766752 let span = fn_decl. output . span ( ) ;
767753 if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span) {
768754 db. span_label (
@@ -774,7 +760,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
774760 true ,
775761 ) ;
776762 } else {
777- coercion. coerce_forced_unit ( self , & cause, & mut |_| ( ) , true ) ;
763+ coercion. coerce_forced_unit ( self , & cause, |_| ( ) , true ) ;
778764 }
779765 }
780766 self . tcx . types . never
0 commit comments