Skip to content

Commit f6fcfa3

Browse files
committed
normalize the results of tcx.type_of after substituting
Also remove `def_ty`, which was a footgun because it did not do the above.
1 parent 88866b5 commit f6fcfa3

File tree

7 files changed

+14
-21
lines changed

7 files changed

+14
-21
lines changed

src/librustc/traits/trans/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use dep_graph::{DepKind, DepTrackingMapConfig};
1717
use infer::TransNormalize;
1818
use std::marker::PhantomData;
1919
use syntax_pos::DUMMY_SP;
20+
use hir::def_id::DefId;
2021
use traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext, Vtable};
2122
use ty::{self, Ty, TyCtxt};
2223
use ty::subst::{Subst, Substs};
@@ -119,6 +120,12 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
119120
let substituted = self.erase_regions(&substituted);
120121
AssociatedTypeNormalizerEnv::new(self, param_env).fold(&substituted)
121122
}
123+
124+
pub fn trans_impl_self_ty(&self, def_id: DefId, substs: &'tcx Substs<'tcx>)
125+
-> Ty<'tcx>
126+
{
127+
self.trans_apply_param_substs(substs, &self.type_of(def_id))
128+
}
122129
}
123130

124131
struct AssociatedTypeNormalizer<'a, 'gcx: 'a> {
@@ -214,4 +221,3 @@ impl<'gcx> DepTrackingMapConfig for ProjectionCache<'gcx> {
214221
DepKind::TraitSelect
215222
}
216223
}
217-

src/librustc/ty/instance.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'a, 'tcx> Instance<'tcx> {
5050
tcx: TyCtxt<'a, 'tcx, 'tcx>)
5151
-> Ty<'tcx>
5252
{
53-
let ty = self.def.def_ty(tcx);
53+
let ty = tcx.type_of(self.def.def_id());
5454
tcx.trans_apply_param_substs(self.substs, &ty)
5555
}
5656
}
@@ -69,11 +69,6 @@ impl<'tcx> InstanceDef<'tcx> {
6969
}
7070
}
7171

72-
#[inline]
73-
pub fn def_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
74-
tcx.type_of(self.def_id())
75-
}
76-
7772
#[inline]
7873
pub fn attrs<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ty::Attributes<'tcx> {
7974
tcx.get_attrs(self.def_id())

src/librustc_mir/interpret/const_eval.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ pub fn eval_body<'a, 'tcx>(
5757
if ecx.tcx.has_attr(instance.def_id(), "linkage") {
5858
return Err(ConstEvalError::NotConst("extern global".to_string()).into());
5959
}
60-
// FIXME(eddyb) use `Instance::ty` when it becomes available.
61-
let instance_ty =
62-
ecx.monomorphize(instance.def.def_ty(tcx), instance.substs);
60+
let instance_ty = instance.ty(tcx);
6361
if tcx.interpret_interner.borrow().get_cached(cid).is_none() {
6462
let mir = ecx.load_mir(instance.def)?;
6563
let layout = ecx.layout_of(instance_ty)?;

src/librustc_mir/interpret/step.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
172172
M::global_item_with_linkage(self, cid.instance, mutability)?;
173173
return Ok(false);
174174
}
175-
// FIXME(eddyb) use `Instance::ty` when it becomes available.
176-
let instance_ty =
177-
self.monomorphize(instance.def.def_ty(self.tcx), instance.substs);
175+
let instance_ty = instance.ty(self.tcx);
178176
let layout = self.layout_of(instance_ty)?;
179177
assert!(!layout.is_unsized());
180178
let ptr = self.memory.allocate(

src/librustc_mir/interpret/terminator/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
7272
ty::TyFnPtr(sig) => {
7373
let fn_ptr = self.value_to_primval(func)?.to_ptr()?;
7474
let instance = self.memory.get_fn(fn_ptr)?;
75-
// FIXME(eddyb) use `Instance::ty` when it becomes available.
76-
let instance_ty =
77-
self.monomorphize(instance.def.def_ty(self.tcx), instance.substs);
75+
let instance_ty = instance.ty(self.tcx);
7876
match instance_ty.sty {
7977
ty::TyFnDef(..) => {
8078
let real_sig = instance_ty.fn_sig(self.tcx);

src/librustc_mir/monomorphize/partitioning.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ use syntax::ast::NodeId;
115115
use syntax::symbol::{Symbol, InternedString};
116116
use rustc::mir::mono::MonoItem;
117117
use monomorphize::item::{MonoItemExt, InstantiationMode};
118-
use rustc::ty::subst::Subst;
119118

120119
pub use rustc::mir::mono::CodegenUnit;
121120

@@ -576,7 +575,7 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
576575
if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
577576
// This is a method within an inherent impl, find out what the
578577
// self-type is:
579-
let impl_self_ty = tcx.type_of(impl_def_id).subst(tcx, instance.substs);
578+
let impl_self_ty = tcx.trans_impl_self_ty(impl_def_id, instance.substs);
580579
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
581580
return Some(def_id);
582581
}

src/librustc_trans/debuginfo/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use llvm;
2424
use llvm::{ModuleRef, ContextRef, ValueRef};
2525
use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArray, DIFlags};
2626
use rustc::hir::def_id::{DefId, CrateNum};
27-
use rustc::ty::subst::{Subst, Substs};
27+
use rustc::ty::subst::Substs;
2828

2929
use abi::Abi;
3030
use common::CrateContext;
@@ -427,8 +427,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
427427
let self_type = cx.tcx().impl_of_method(instance.def_id()).and_then(|impl_def_id| {
428428
// If the method does *not* belong to a trait, proceed
429429
if cx.tcx().trait_id_of_impl(impl_def_id).is_none() {
430-
let impl_self_ty =
431-
cx.tcx().type_of(impl_def_id).subst(cx.tcx(), instance.substs);
430+
let impl_self_ty = cx.tcx().trans_impl_self_ty(impl_def_id, instance.substs);
432431

433432
// Only "class" methods are generally understood by LLVM,
434433
// so avoid methods on other types (e.g. `<*mut T>::null`).

0 commit comments

Comments
 (0)