mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
normalize the results of tcx.type_of
after substituting
Also remove `def_ty`, which was a footgun because it did not do the above.
This commit is contained in:
parent
88866b5c85
commit
f6fcfa3915
@ -17,6 +17,7 @@ use dep_graph::{DepKind, DepTrackingMapConfig};
|
||||
use infer::TransNormalize;
|
||||
use std::marker::PhantomData;
|
||||
use syntax_pos::DUMMY_SP;
|
||||
use hir::def_id::DefId;
|
||||
use traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext, Vtable};
|
||||
use ty::{self, Ty, TyCtxt};
|
||||
use ty::subst::{Subst, Substs};
|
||||
@ -119,6 +120,12 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
let substituted = self.erase_regions(&substituted);
|
||||
AssociatedTypeNormalizerEnv::new(self, param_env).fold(&substituted)
|
||||
}
|
||||
|
||||
pub fn trans_impl_self_ty(&self, def_id: DefId, substs: &'tcx Substs<'tcx>)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
self.trans_apply_param_substs(substs, &self.type_of(def_id))
|
||||
}
|
||||
}
|
||||
|
||||
struct AssociatedTypeNormalizer<'a, 'gcx: 'a> {
|
||||
@ -214,4 +221,3 @@ impl<'gcx> DepTrackingMapConfig for ProjectionCache<'gcx> {
|
||||
DepKind::TraitSelect
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ impl<'a, 'tcx> Instance<'tcx> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
let ty = self.def.def_ty(tcx);
|
||||
let ty = tcx.type_of(self.def.def_id());
|
||||
tcx.trans_apply_param_substs(self.substs, &ty)
|
||||
}
|
||||
}
|
||||
@ -69,11 +69,6 @@ impl<'tcx> InstanceDef<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn def_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
|
||||
tcx.type_of(self.def_id())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn attrs<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ty::Attributes<'tcx> {
|
||||
tcx.get_attrs(self.def_id())
|
||||
|
@ -57,9 +57,7 @@ pub fn eval_body<'a, 'tcx>(
|
||||
if ecx.tcx.has_attr(instance.def_id(), "linkage") {
|
||||
return Err(ConstEvalError::NotConst("extern global".to_string()).into());
|
||||
}
|
||||
// FIXME(eddyb) use `Instance::ty` when it becomes available.
|
||||
let instance_ty =
|
||||
ecx.monomorphize(instance.def.def_ty(tcx), instance.substs);
|
||||
let instance_ty = instance.ty(tcx);
|
||||
if tcx.interpret_interner.borrow().get_cached(cid).is_none() {
|
||||
let mir = ecx.load_mir(instance.def)?;
|
||||
let layout = ecx.layout_of(instance_ty)?;
|
||||
|
@ -172,9 +172,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
|
||||
M::global_item_with_linkage(self, cid.instance, mutability)?;
|
||||
return Ok(false);
|
||||
}
|
||||
// FIXME(eddyb) use `Instance::ty` when it becomes available.
|
||||
let instance_ty =
|
||||
self.monomorphize(instance.def.def_ty(self.tcx), instance.substs);
|
||||
let instance_ty = instance.ty(self.tcx);
|
||||
let layout = self.layout_of(instance_ty)?;
|
||||
assert!(!layout.is_unsized());
|
||||
let ptr = self.memory.allocate(
|
||||
|
@ -72,9 +72,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
|
||||
ty::TyFnPtr(sig) => {
|
||||
let fn_ptr = self.value_to_primval(func)?.to_ptr()?;
|
||||
let instance = self.memory.get_fn(fn_ptr)?;
|
||||
// FIXME(eddyb) use `Instance::ty` when it becomes available.
|
||||
let instance_ty =
|
||||
self.monomorphize(instance.def.def_ty(self.tcx), instance.substs);
|
||||
let instance_ty = instance.ty(self.tcx);
|
||||
match instance_ty.sty {
|
||||
ty::TyFnDef(..) => {
|
||||
let real_sig = instance_ty.fn_sig(self.tcx);
|
||||
|
@ -115,7 +115,6 @@ use syntax::ast::NodeId;
|
||||
use syntax::symbol::{Symbol, InternedString};
|
||||
use rustc::mir::mono::MonoItem;
|
||||
use monomorphize::item::{MonoItemExt, InstantiationMode};
|
||||
use rustc::ty::subst::Subst;
|
||||
|
||||
pub use rustc::mir::mono::CodegenUnit;
|
||||
|
||||
@ -576,7 +575,7 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
|
||||
// This is a method within an inherent impl, find out what the
|
||||
// self-type is:
|
||||
let impl_self_ty = tcx.type_of(impl_def_id).subst(tcx, instance.substs);
|
||||
let impl_self_ty = tcx.trans_impl_self_ty(impl_def_id, instance.substs);
|
||||
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
|
||||
return Some(def_id);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use llvm;
|
||||
use llvm::{ModuleRef, ContextRef, ValueRef};
|
||||
use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArray, DIFlags};
|
||||
use rustc::hir::def_id::{DefId, CrateNum};
|
||||
use rustc::ty::subst::{Subst, Substs};
|
||||
use rustc::ty::subst::Substs;
|
||||
|
||||
use abi::Abi;
|
||||
use common::CrateContext;
|
||||
@ -427,8 +427,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
let self_type = cx.tcx().impl_of_method(instance.def_id()).and_then(|impl_def_id| {
|
||||
// If the method does *not* belong to a trait, proceed
|
||||
if cx.tcx().trait_id_of_impl(impl_def_id).is_none() {
|
||||
let impl_self_ty =
|
||||
cx.tcx().type_of(impl_def_id).subst(cx.tcx(), instance.substs);
|
||||
let impl_self_ty = cx.tcx().trans_impl_self_ty(impl_def_id, instance.substs);
|
||||
|
||||
// Only "class" methods are generally understood by LLVM,
|
||||
// so avoid methods on other types (e.g. `<*mut T>::null`).
|
||||
|
Loading…
Reference in New Issue
Block a user