@@ -17,7 +17,7 @@ use rustc::hir;
17
17
use rustc:: hir:: def_id:: { DefId , DefIndex } ;
18
18
use rustc:: hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
19
19
use rustc:: infer:: InferCtxt ;
20
- use rustc:: ty:: { self , Ty , TyCtxt } ;
20
+ use rustc:: ty:: { self , Ty , TyCtxt , TypeVariants } ;
21
21
use rustc:: ty:: adjustment:: { Adjust , Adjustment } ;
22
22
use rustc:: ty:: fold:: { TypeFoldable , TypeFolder } ;
23
23
use rustc:: util:: nodemap:: DefIdSet ;
@@ -168,14 +168,23 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
168
168
fn fix_index_builtin_expr ( & mut self , e : & hir:: Expr ) {
169
169
if let hir:: ExprIndex ( ref base, ref index) = e. node {
170
170
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
+
174
184
let index_ty = tables. expr_ty_adjusted ( & index) ;
175
185
let index_ty = self . fcx . resolve_type_vars_if_possible ( & index_ty) ;
176
186
177
187
if base_ty. builtin_index ( ) . is_some ( ) && index_ty. is_uint ( ) {
178
-
179
188
// Remove the method call record, which blocks use in
180
189
// constant or static cases
181
190
tables. type_dependent_defs_mut ( ) . remove ( e. hir_id ) ;
0 commit comments