Skip to content

Commit 21ddc18

Browse files
committed
Fixed unsize changing adjusted type
If the final type coming out of an Adjust is a ref, it is deconstructed. Also made some formatting changes.
1 parent 8ec3696 commit 21ddc18

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/librustc_typeck/check/writeback.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::hir;
1717
use rustc::hir::def_id::{DefId, DefIndex};
1818
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
1919
use rustc::infer::InferCtxt;
20-
use rustc::ty::{self, Ty, TyCtxt};
20+
use rustc::ty::{self, Ty, TyCtxt, TypeVariants};
2121
use rustc::ty::adjustment::{Adjust, Adjustment};
2222
use rustc::ty::fold::{TypeFoldable, TypeFolder};
2323
use 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

Comments
 (0)