@@ -17,7 +17,7 @@ use rustc::hir;
1717use rustc:: hir:: def_id:: { DefId , DefIndex } ;
1818use rustc:: hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
1919use rustc:: infer:: InferCtxt ;
20- use rustc:: ty:: { self , Ty , TyCtxt } ;
20+ use rustc:: ty:: { self , Ty , TyCtxt , TypeVariants } ;
2121use rustc:: ty:: adjustment:: { Adjust , Adjustment } ;
2222use rustc:: ty:: fold:: { TypeFoldable , TypeFolder } ;
2323use rustc:: util:: nodemap:: DefIdSet ;
@@ -168,14 +168,23 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
168168 fn fix_index_builtin_expr ( & mut self , e : & hir:: Expr ) {
169169 if let hir:: ExprIndex ( ref base, ref index) = e. node {
170170 let mut tables = self . fcx . tables . borrow_mut ( ) ;
171-
172- let base_ty = tables. expr_ty_adjusted ( & base) ;
173- let base_ty = self . fcx . resolve_type_vars_if_possible ( & base_ty) ;
171+
172+ let base_ty = {
173+ let base_ty = tables. expr_ty_adjusted ( & base) ;
174+ // When unsizing, the final type of the expression is taken
175+ // from the first argument of the indexing operator, which
176+ // is a &self, and has to be deconstructed
177+ if let TypeVariants :: TyRef ( _, ref ref_to) = base_ty. sty {
178+ ref_to. ty
179+ } else {
180+ base_ty
181+ }
182+ } ;
183+
174184 let index_ty = tables. expr_ty_adjusted ( & index) ;
175185 let index_ty = self . fcx . resolve_type_vars_if_possible ( & index_ty) ;
176186
177187 if base_ty. builtin_index ( ) . is_some ( ) && index_ty. is_uint ( ) {
178-
179188 // Remove the method call record, which blocks use in
180189 // constant or static cases
181190 tables. type_dependent_defs_mut ( ) . remove ( e. hir_id ) ;
0 commit comments