@@ -114,29 +114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
114114 self . check_method_call ( expr, segment, span, args, expected, needs)
115115 }
116116 ExprKind :: Cast ( ref e, ref t) => {
117- // Find the type of `e`. Supply hints based on the type we are casting to,
118- // if appropriate.
119- let t_cast = self . to_ty_saving_user_provided_ty ( t) ;
120- let t_cast = self . resolve_vars_if_possible ( & t_cast) ;
121- let t_expr = self . check_expr_with_expectation ( e, ExpectCastableToType ( t_cast) ) ;
122- let t_cast = self . resolve_vars_if_possible ( & t_cast) ;
123-
124- // Eagerly check for some obvious errors.
125- if t_expr. references_error ( ) || t_cast. references_error ( ) {
126- tcx. types . err
127- } else {
128- // Defer other checks until we're done type checking.
129- let mut deferred_cast_checks = self . deferred_cast_checks . borrow_mut ( ) ;
130- match cast:: CastCheck :: new ( self , e, t_expr, t_cast, t. span , expr. span ) {
131- Ok ( cast_check) => {
132- deferred_cast_checks. push ( cast_check) ;
133- t_cast
134- }
135- Err ( ErrorReported ) => {
136- tcx. types . err
137- }
138- }
139- }
117+ self . check_expr_cast ( e, t, expr)
140118 }
141119 ExprKind :: Type ( ref e, ref t) => {
142120 let ty = self . to_ty_saving_user_provided_ty ( & t) ;
@@ -806,4 +784,35 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
806784 }
807785 ctxt. coerce . map ( |c| c. complete ( self ) ) . unwrap_or_else ( || self . tcx . mk_unit ( ) )
808786 }
787+
788+ fn check_expr_cast (
789+ & self ,
790+ e : & ' tcx hir:: Expr ,
791+ t : & ' tcx hir:: Ty ,
792+ expr : & ' tcx hir:: Expr ,
793+ ) -> Ty < ' tcx > {
794+ // Find the type of `e`. Supply hints based on the type we are casting to,
795+ // if appropriate.
796+ let t_cast = self . to_ty_saving_user_provided_ty ( t) ;
797+ let t_cast = self . resolve_vars_if_possible ( & t_cast) ;
798+ let t_expr = self . check_expr_with_expectation ( e, ExpectCastableToType ( t_cast) ) ;
799+ let t_cast = self . resolve_vars_if_possible ( & t_cast) ;
800+
801+ // Eagerly check for some obvious errors.
802+ if t_expr. references_error ( ) || t_cast. references_error ( ) {
803+ self . tcx . types . err
804+ } else {
805+ // Defer other checks until we're done type checking.
806+ let mut deferred_cast_checks = self . deferred_cast_checks . borrow_mut ( ) ;
807+ match cast:: CastCheck :: new ( self , e, t_expr, t_cast, t. span , expr. span ) {
808+ Ok ( cast_check) => {
809+ deferred_cast_checks. push ( cast_check) ;
810+ t_cast
811+ }
812+ Err ( ErrorReported ) => {
813+ self . tcx . types . err
814+ }
815+ }
816+ }
817+ }
809818}
0 commit comments