@@ -2357,6 +2357,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2357
2357
t
2358
2358
}
2359
2359
2360
+ pub fn to_ty_saving_user_provided_ty ( & self , ast_ty : & hir:: Ty ) -> Ty < ' tcx > {
2361
+ let ty = self . to_ty ( ast_ty) ;
2362
+ let c_ty = self . infcx . canonicalize_response ( & ty) ;
2363
+ self . tables . borrow_mut ( ) . user_provided_tys_mut ( ) . insert ( ast_ty. hir_id , c_ty) ;
2364
+ ty
2365
+ }
2366
+
2360
2367
pub fn node_ty ( & self , id : hir:: HirId ) -> Ty < ' tcx > {
2361
2368
match self . tables . borrow ( ) . node_types ( ) . get ( id) {
2362
2369
Some ( & t) => t,
@@ -4153,7 +4160,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4153
4160
hir:: ExprKind :: Cast ( ref e, ref t) => {
4154
4161
// Find the type of `e`. Supply hints based on the type we are casting to,
4155
4162
// if appropriate.
4156
- let t_cast = self . to_ty ( t) ;
4163
+ let t_cast = self . to_ty_saving_user_provided_ty ( t) ;
4157
4164
let t_cast = self . resolve_type_vars_if_possible ( & t_cast) ;
4158
4165
let t_expr = self . check_expr_with_expectation ( e, ExpectCastableToType ( t_cast) ) ;
4159
4166
let t_cast = self . resolve_type_vars_if_possible ( & t_cast) ;
@@ -4166,8 +4173,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4166
4173
let mut deferred_cast_checks = self . deferred_cast_checks . borrow_mut ( ) ;
4167
4174
match cast:: CastCheck :: new ( self , e, t_expr, t_cast, t. span , expr. span ) {
4168
4175
Ok ( cast_check) => {
4169
- let c_ty = self . infcx . canonicalize_response ( & t_cast) ;
4170
- self . tables . borrow_mut ( ) . user_provided_tys_mut ( ) . insert ( t. hir_id , c_ty) ;
4171
4176
deferred_cast_checks. push ( cast_check) ;
4172
4177
t_cast
4173
4178
}
@@ -4178,10 +4183,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4178
4183
}
4179
4184
}
4180
4185
hir:: ExprKind :: Type ( ref e, ref t) => {
4181
- let ty = self . to_ty ( & t) ;
4186
+ let ty = self . to_ty_saving_user_provided_ty ( & t) ;
4182
4187
self . check_expr_eq_type ( & e, ty) ;
4183
- let c_ty = self . infcx . canonicalize_response ( & ty) ;
4184
- self . tables . borrow_mut ( ) . user_provided_tys_mut ( ) . insert ( t. hir_id , c_ty) ;
4185
4188
ty
4186
4189
}
4187
4190
hir:: ExprKind :: Array ( ref args) => {
0 commit comments