Skip to content

Commit ab79cf9

Browse files
committed
save the user-provided type immediately upon return from astconv
1 parent 2d98e9e commit ab79cf9

File tree

1 file changed

+9
-6
lines changed
  • src/librustc_typeck/check

1 file changed

+9
-6
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,6 +2357,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
23572357
t
23582358
}
23592359

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+
23602367
pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> {
23612368
match self.tables.borrow().node_types().get(id) {
23622369
Some(&t) => t,
@@ -4153,7 +4160,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
41534160
hir::ExprKind::Cast(ref e, ref t) => {
41544161
// Find the type of `e`. Supply hints based on the type we are casting to,
41554162
// if appropriate.
4156-
let t_cast = self.to_ty(t);
4163+
let t_cast = self.to_ty_saving_user_provided_ty(t);
41574164
let t_cast = self.resolve_type_vars_if_possible(&t_cast);
41584165
let t_expr = self.check_expr_with_expectation(e, ExpectCastableToType(t_cast));
41594166
let t_cast = self.resolve_type_vars_if_possible(&t_cast);
@@ -4166,8 +4173,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
41664173
let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
41674174
match cast::CastCheck::new(self, e, t_expr, t_cast, t.span, expr.span) {
41684175
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);
41714176
deferred_cast_checks.push(cast_check);
41724177
t_cast
41734178
}
@@ -4178,10 +4183,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
41784183
}
41794184
}
41804185
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);
41824187
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);
41854188
ty
41864189
}
41874190
hir::ExprKind::Array(ref args) => {

0 commit comments

Comments
 (0)