Skip to content

Commit

Permalink
Fixed unsize changing adjusted type
Browse files Browse the repository at this point in the history
If the final type coming out of an Adjust is a ref, it is deconstructed.
Also made some formatting changes.
  • Loading branch information
ivanbakel committed Jan 7, 2018
1 parent 8ec3696 commit 21ddc18
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/librustc_typeck/check/writeback.rs
Expand Up @@ -17,7 +17,7 @@ use rustc::hir;
use rustc::hir::def_id::{DefId, DefIndex};
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc::infer::InferCtxt;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::{self, Ty, TyCtxt, TypeVariants};
use rustc::ty::adjustment::{Adjust, Adjustment};
use rustc::ty::fold::{TypeFoldable, TypeFolder};
use rustc::util::nodemap::DefIdSet;
Expand Down Expand Up @@ -168,14 +168,23 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
fn fix_index_builtin_expr(&mut self, e: &hir::Expr) {
if let hir::ExprIndex(ref base, ref index) = e.node {
let mut tables = self.fcx.tables.borrow_mut();

let base_ty = tables.expr_ty_adjusted(&base);
let base_ty = self.fcx.resolve_type_vars_if_possible(&base_ty);

let base_ty = {
let base_ty = tables.expr_ty_adjusted(&base);
// When unsizing, the final type of the expression is taken
// from the first argument of the indexing operator, which
// is a &self, and has to be deconstructed
if let TypeVariants::TyRef(_, ref ref_to) = base_ty.sty {
ref_to.ty
} else {
base_ty
}
};

let index_ty = tables.expr_ty_adjusted(&index);
let index_ty = self.fcx.resolve_type_vars_if_possible(&index_ty);

if base_ty.builtin_index().is_some() && index_ty.is_uint() {

// Remove the method call record, which blocks use in
// constant or static cases
tables.type_dependent_defs_mut().remove(e.hir_id);
Expand Down

0 comments on commit 21ddc18

Please sign in to comment.