Rollup merge of #37688 - eddyb:lazy-8, r=petrochenkov

[8/n] rustc: clean up lookup_item_type and remove TypeScheme.

_This is part of a series ([prev](https://github.com/rust-lang/rust/pull/37676) | [next]()) of patches designed to rework rustc into an out-of-order on-demand pipeline model for both better feature support (e.g. [MIR-based](https://github.com/solson/miri) early constant evaluation) and incremental execution of compiler passes (e.g. type-checking), with beneficial consequences to IDE support as well.
If any motivation is unclear, please ask for additional PR description clarifications or code comments._

<hr>

* `tcx.tcache` -> `tcx.item_types`
* `TypeScheme` (grouping `Ty` and `ty::Generics`) is removed
* `tcx.item_types` entries no longer duplicated in `tcx.tables.node_types`
* `tcx.lookup_item_type(def_id).ty` -> `tcx.item_type(def_id)`
* `tcx.lookup_item_type(def_id).generics` -> `tcx.item_generics(def_id)`
* `tcx.lookup_generics(def_id)` -> `tcx.item_generics(def_id)`
* `tcx.lookup_{super_,}predicates(def_id)` -> `tcx.item_{super_,}predicates(def_id)`
This commit is contained in:
Eduard-Mihai Burtescu 2016-11-12 10:38:41 +02:00 committed by GitHub
commit 6dd4ee6d08
61 changed files with 399 additions and 491 deletions

View File

@ -112,15 +112,15 @@ impl<M: DepTrackingMapConfig> MemoizationMap for RefCell<DepTrackingMap<M>> {
/// switched to `Map(key)`. Therefore, if `op` makes use of any
/// HIR nodes or shared state accessed through its closure
/// environment, it must explicitly register a read of that
/// state. As an example, see `type_scheme_of_item` in `collect`,
/// state. As an example, see `type_of_item` in `collect`,
/// which looks something like this:
///
/// ```
/// fn type_scheme_of_item(..., item: &hir::Item) -> ty::TypeScheme<'tcx> {
/// fn type_of_item(..., item: &hir::Item) -> Ty<'tcx> {
/// let item_def_id = ccx.tcx.map.local_def_id(it.id);
/// ccx.tcx.tcache.memoized(item_def_id, || {
/// ccx.tcx.item_types.memoized(item_def_id, || {
/// ccx.tcx.dep_graph.read(DepNode::Hir(item_def_id)); // (*)
/// compute_type_scheme_of_item(ccx, item)
/// compute_type_of_item(ccx, item)
/// });
/// }
/// ```

View File

@ -1443,7 +1443,7 @@ impl<'a, 'gcx, 'tcx> Rebuilder<'a, 'gcx, 'tcx> {
match self.tcx.expect_def(cur_ty.id) {
Def::Enum(did) | Def::TyAlias(did) |
Def::Struct(did) | Def::Union(did) => {
let generics = self.tcx.lookup_generics(did);
let generics = self.tcx.item_generics(did);
let expected =
generics.regions.len() as u32;

View File

@ -433,7 +433,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
}
fn should_warn_about_field(&mut self, field: &hir::StructField) -> bool {
let field_type = self.tcx.tables().node_id_to_type(field.id);
let field_type = self.tcx.item_type(self.tcx.map.local_def_id(field.id));
let is_marker_field = match field_type.ty_to_def_id() {
Some(def_id) => self.tcx.lang_items.items().iter().any(|item| *item == Some(def_id)),
_ => false

View File

@ -51,7 +51,7 @@ struct ExprVisitor<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
fn def_id_is_transmute(&self, def_id: DefId) -> bool {
let intrinsic = match self.infcx.tcx.lookup_item_type(def_id).ty.sty {
let intrinsic = match self.infcx.tcx.item_type(def_id).sty {
ty::TyFnDef(.., ref bfty) => bfty.abi == RustIntrinsic,
_ => return false
};

View File

@ -112,7 +112,7 @@ use self::VarKind::*;
use dep_graph::DepNode;
use hir::def::*;
use hir::pat_util;
use ty::{self, Ty, TyCtxt, ParameterEnvironment};
use ty::{self, TyCtxt, ParameterEnvironment};
use traits::{self, Reveal};
use ty::subst::Subst;
use lint;
@ -1440,28 +1440,30 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
}
impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn fn_ret(&self, id: NodeId) -> ty::Binder<Ty<'tcx>> {
let fn_ty = self.ir.tcx.tables().node_id_to_type(id);
match fn_ty.sty {
ty::TyClosure(closure_def_id, substs) =>
self.ir.tcx.closure_type(closure_def_id, substs).sig.output(),
_ => fn_ty.fn_ret()
}
}
fn check_ret(&self,
id: NodeId,
sp: Span,
_fk: FnKind,
fk: FnKind,
entry_ln: LiveNode,
body: &hir::Expr)
{
let fn_ty = if let FnKind::Closure(_) = fk {
self.ir.tcx.tables().node_id_to_type(id)
} else {
self.ir.tcx.item_type(self.ir.tcx.map.local_def_id(id))
};
let fn_ret = match fn_ty.sty {
ty::TyClosure(closure_def_id, substs) =>
self.ir.tcx.closure_type(closure_def_id, substs).sig.output(),
_ => fn_ty.fn_ret()
};
// within the fn body, late-bound regions are liberated
// and must outlive the *call-site* of the function.
let fn_ret =
self.ir.tcx.liberate_late_bound_regions(
self.ir.tcx.region_maps.call_site_extent(id, body.id),
&self.fn_ret(id));
&fn_ret);
if !fn_ret.is_never() && self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {
let param_env = ParameterEnvironment::for_item(self.ir.tcx, id);

View File

@ -125,7 +125,7 @@ impl<'tcx> Lvalue<'tcx> {
Lvalue::Local(index) =>
LvalueTy::Ty { ty: mir.local_decls[index].ty },
Lvalue::Static(def_id) =>
LvalueTy::Ty { ty: tcx.lookup_item_type(def_id).ty },
LvalueTy::Ty { ty: tcx.item_type(def_id) },
Lvalue::Projection(ref proj) =>
proj.base.ty(mir, tcx).projection_ty(tcx, &proj.elem),
}
@ -188,7 +188,7 @@ impl<'tcx> Rvalue<'tcx> {
))
}
AggregateKind::Adt(def, _, substs, _) => {
Some(tcx.lookup_item_type(def.did).ty.subst(tcx, substs))
Some(tcx.item_type(def.did).subst(tcx, substs))
}
AggregateKind::Closure(did, substs) => {
Some(tcx.mk_closure_from_closure_substs(did, substs))

View File

@ -154,9 +154,13 @@ impl<'a, 'gcx, 'tcx> DeferredObligation<'tcx> {
pub fn try_select(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>)
-> Option<Vec<PredicateObligation<'tcx>>> {
if let ty::TyAnon(def_id, substs) = self.predicate.skip_binder().self_ty().sty {
let ty = if def_id.is_local() {
tcx.item_types.borrow().get(&def_id).cloned()
} else {
Some(tcx.item_type(def_id))
};
// We can resolve the `impl Trait` to its concrete type.
if let Some(ty_scheme) = tcx.opt_lookup_item_type(def_id) {
let concrete_ty = ty_scheme.ty.subst(tcx, substs);
if let Some(concrete_ty) = ty.subst(tcx, substs) {
let predicate = ty::TraitRef {
def_id: self.predicate.def_id(),
substs: tcx.mk_substs_trait(concrete_ty, &[])

View File

@ -603,7 +603,7 @@ pub fn get_vtable_methods<'a, 'tcx>(
// do not hold for this particular set of type parameters.
// Note that this method could then never be called, so we
// do not want to try and trans it, in that case (see #23435).
let predicates = tcx.lookup_predicates(def_id).instantiate_own(tcx, substs);
let predicates = tcx.item_predicates(def_id).instantiate_own(tcx, substs);
if !normalize_and_test_predicates(tcx, predicates.predicates) {
debug!("get_vtable_methods: predicates do not hold");
return None;

View File

@ -129,7 +129,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
let trait_def = self.lookup_trait_def(trait_def_id);
let trait_ref = trait_def.trait_ref.clone();
let trait_ref = trait_ref.to_poly_trait_ref();
let predicates = self.lookup_super_predicates(trait_def_id);
let predicates = self.item_super_predicates(trait_def_id);
predicates
.predicates
.into_iter()
@ -166,7 +166,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// Search for a predicate like `Self : Sized` amongst the trait bounds.
let free_substs = self.construct_free_substs(def_id,
self.region_maps.node_extent(ast::DUMMY_NODE_ID));
let predicates = self.lookup_predicates(def_id);
let predicates = self.item_predicates(def_id);
let predicates = predicates.instantiate(self, free_substs).predicates;
elaborate_predicates(self, predicates)
.any(|predicate| {
@ -238,7 +238,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// The `Self` type is erased, so it should not appear in list of
// arguments or return type apart from the receiver.
let ref sig = self.lookup_item_type(method.def_id).ty.fn_sig();
let ref sig = self.item_type(method.def_id).fn_sig();
for &input_ty in &sig.0.inputs[1..] {
if self.contains_illegal_self_type_reference(trait_def_id, input_ty) {
return Some(MethodViolationCode::ReferencesSelf);
@ -249,7 +249,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
// We can't monomorphize things like `fn foo<A>(...)`.
if !self.lookup_generics(method.def_id).types.is_empty() {
if !self.item_generics(method.def_id).types.is_empty() {
return Some(MethodViolationCode::Generic);
}

View File

@ -311,7 +311,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a,
ty::TyAnon(def_id, substs) if !substs.has_escaping_regions() => { // (*)
// Only normalize `impl Trait` after type-checking, usually in trans.
if self.selcx.projection_mode() == Reveal::All {
let generic_ty = self.tcx().lookup_item_type(def_id).ty;
let generic_ty = self.tcx().item_type(def_id);
let concrete_ty = generic_ty.subst(self.tcx(), substs);
self.fold_ty(concrete_ty)
} else {
@ -809,7 +809,7 @@ fn assemble_candidates_from_trait_def<'cx, 'gcx, 'tcx>(
};
// If so, extract what we know from the trait and try to come up with a good answer.
let trait_predicates = selcx.tcx().lookup_predicates(def_id);
let trait_predicates = selcx.tcx().item_predicates(def_id);
let bounds = trait_predicates.instantiate(selcx.tcx(), substs);
let bounds = elaborate_predicates(selcx.tcx(), bounds.predicates);
assemble_candidates_from_predicates(selcx,
@ -1313,7 +1313,7 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>(
obligation.predicate.trait_ref);
tcx.types.err
} else {
tcx.lookup_item_type(node_item.item.def_id).ty
tcx.item_type(node_item.item.def_id)
};
let substs = translate_substs(selcx.infcx(), impl_def_id, substs, node_item.node);
Progress {

View File

@ -1200,7 +1200,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
def_id={:?}, substs={:?}",
def_id, substs);
let item_predicates = self.tcx().lookup_predicates(def_id);
let item_predicates = self.tcx().item_predicates(def_id);
let bounds = item_predicates.instantiate(self.tcx(), substs);
debug!("match_projection_obligation_against_definition_bounds: \
bounds={:?}",
@ -2884,7 +2884,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
// obligation will normalize to `<$0 as Iterator>::Item = $1` and
// `$1: Copy`, so we must ensure the obligations are emitted in
// that order.
let predicates = tcx.lookup_predicates(def_id);
let predicates = tcx.item_predicates(def_id);
assert_eq!(predicates.parent, None);
let predicates = predicates.predicates.iter().flat_map(|predicate| {
let predicate = normalize_with_depth(self, cause.clone(), recursion_depth,

View File

@ -128,7 +128,7 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> {
match *predicate {
ty::Predicate::Trait(ref data) => {
// Predicates declared on the trait.
let predicates = tcx.lookup_super_predicates(data.def_id());
let predicates = tcx.item_super_predicates(data.def_id());
let mut predicates: Vec<_> =
predicates.predicates
@ -295,7 +295,7 @@ impl<'cx, 'gcx, 'tcx> Iterator for SupertraitDefIds<'cx, 'gcx, 'tcx> {
None => { return None; }
};
let predicates = self.tcx.lookup_super_predicates(def_id);
let predicates = self.tcx.item_super_predicates(def_id);
let visited = &mut self.visited;
self.stack.extend(
predicates.predicates
@ -362,7 +362,7 @@ pub fn impl_trait_ref_and_oblig<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a,
let Normalized { value: impl_trait_ref, obligations: normalization_obligations1 } =
super::normalize(selcx, ObligationCause::dummy(), &impl_trait_ref);
let predicates = selcx.tcx().lookup_predicates(impl_def_id);
let predicates = selcx.tcx().item_predicates(impl_def_id);
let predicates = predicates.instantiate(selcx.tcx(), impl_substs);
let Normalized { value: predicates, obligations: normalization_obligations2 } =
super::normalize(selcx, ObligationCause::dummy(), &predicates);

View File

@ -444,7 +444,7 @@ pub struct GlobalCtxt<'tcx> {
pub maybe_unused_trait_imports: NodeSet,
// Records the type of every item.
pub tcache: RefCell<DepTrackingMap<maps::Tcache<'tcx>>>,
pub item_types: RefCell<DepTrackingMap<maps::Types<'tcx>>>,
// Internal cache for metadata decoding. No need to track deps on this.
pub rcache: RefCell<FxHashMap<ty::CReaderCacheKey, Ty<'tcx>>>,
@ -665,10 +665,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.ty_param_defs.borrow().get(&node_id).unwrap().clone()
}
pub fn node_type_insert(self, id: NodeId, ty: Ty<'gcx>) {
self.tables.borrow_mut().node_types.insert(id, ty);
}
pub fn alloc_generics(self, generics: ty::Generics<'gcx>)
-> &'gcx ty::Generics<'gcx> {
self.global_interners.arenas.generics.alloc(generics)
@ -815,7 +811,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
mir_map: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
freevars: RefCell::new(freevars),
maybe_unused_trait_imports: maybe_unused_trait_imports,
tcache: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
item_types: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
rcache: RefCell::new(FxHashMap()),
tc_cache: RefCell::new(FxHashMap()),
associated_items: RefCell::new(DepTrackingMap::new(dep_graph.clone())),

View File

@ -218,7 +218,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// users may find it useful. Currently, we omit the parent if
// the impl is either in the same module as the self-type or
// as the trait.
let self_ty = self.lookup_item_type(impl_def_id).ty;
let self_ty = self.item_type(impl_def_id);
let in_self_mod = match characteristic_def_id_of_type(self_ty) {
None => false,
Some(ty_def_id) => self.parent_def_id(ty_def_id) == Some(parent_def_id),

View File

@ -33,7 +33,7 @@ macro_rules! dep_map_ty {
}
dep_map_ty! { AssociatedItems: AssociatedItems(DefId) -> ty::AssociatedItem }
dep_map_ty! { Tcache: ItemSignature(DefId) -> Ty<'tcx> }
dep_map_ty! { Types: ItemSignature(DefId) -> Ty<'tcx> }
dep_map_ty! { Generics: ItemSignature(DefId) -> &'tcx ty::Generics<'tcx> }
dep_map_ty! { Predicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx> }
dep_map_ty! { SuperPredicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx> }

View File

@ -169,9 +169,9 @@ impl<'a, 'gcx, 'tcx> ImplHeader<'tcx> {
let header = ImplHeader {
impl_def_id: impl_def_id,
self_ty: tcx.lookup_item_type(impl_def_id).ty,
self_ty: tcx.item_type(impl_def_id),
trait_ref: tcx.impl_trait_ref(impl_def_id),
predicates: tcx.lookup_predicates(impl_def_id).predicates
predicates: tcx.item_predicates(impl_def_id).predicates
}.subst(tcx, impl_substs);
let traits::Normalized { value: mut header, obligations } =
@ -708,7 +708,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
instantiated: &mut InstantiatedPredicates<'tcx>,
substs: &Substs<'tcx>) {
if let Some(def_id) = self.parent {
tcx.lookup_predicates(def_id).instantiate_into(tcx, instantiated, substs);
tcx.item_predicates(def_id).instantiate_into(tcx, instantiated, substs);
}
instantiated.predicates.extend(self.predicates.iter().map(|p| p.subst(tcx, substs)))
}
@ -1301,31 +1301,6 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> {
}
}
/// A "type scheme", in ML terminology, is a type combined with some
/// set of generic types that the type is, well, generic over. In Rust
/// terms, it is the "type" of a fn item or struct -- this type will
/// include various generic parameters that must be substituted when
/// the item/struct is referenced. That is called converting the type
/// scheme to a monotype.
///
/// - `generics`: the set of type parameters and their bounds
/// - `ty`: the base types, which may reference the parameters defined
/// in `generics`
///
/// Note that TypeSchemes are also sometimes called "polytypes" (and
/// in fact this struct used to carry that name, so you may find some
/// stray references in a comment or something). We try to reserve the
/// "poly" prefix to refer to higher-ranked things, as in
/// `PolyTraitRef`.
///
/// Note that each item also comes with predicates, see
/// `lookup_predicates`.
#[derive(Clone, Debug)]
pub struct TypeScheme<'tcx> {
pub generics: &'tcx Generics<'tcx>,
pub ty: Ty<'tcx>,
}
bitflags! {
flags AdtFlags: u32 {
const NO_ADT_FLAGS = 0,
@ -1359,8 +1334,6 @@ pub struct VariantDefData<'tcx, 'container: 'tcx> {
}
pub struct FieldDefData<'tcx, 'container: 'tcx> {
/// The field's DefId. NOTE: the fields of tuple-like enum variants
/// are not real items, and don't have entries in tcache etc.
pub did: DefId,
pub name: Name,
pub vis: Visibility,
@ -1541,14 +1514,9 @@ impl<'a, 'gcx, 'tcx, 'container> AdtDefData<'gcx, 'container> {
&self.variants[0]
}
#[inline]
pub fn type_scheme(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> TypeScheme<'gcx> {
tcx.lookup_item_type(self.did)
}
#[inline]
pub fn predicates(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> GenericPredicates<'gcx> {
tcx.lookup_predicates(self.did)
tcx.item_predicates(self.did)
}
/// Returns an iterator over all fields contained
@ -1784,7 +1752,7 @@ impl<'a, 'tcx> AdtDefData<'tcx, 'tcx> {
def_id: sized_trait,
substs: tcx.mk_substs_trait(ty, &[])
}).to_predicate();
let predicates = tcx.lookup_predicates(self.did).predicates;
let predicates = tcx.item_predicates(self.did).predicates;
if predicates.into_iter().any(|p| p == sized_predicate) {
vec![]
} else {
@ -1963,7 +1931,7 @@ impl LvaluePreference {
}
/// Helper for looking things up in the various maps that are populated during
/// typeck::collect (e.g., `tcx.associated_items`, `tcx.tcache`, etc). All of
/// typeck::collect (e.g., `tcx.associated_items`, `tcx.types`, etc). All of
/// these share the pattern that if the id is local, it should have been loaded
/// into the map by the `typeck::collect` phase. If the def-id is external,
/// then we have to go consult the crate loading code (and cache the result for
@ -2351,38 +2319,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
}
// Register a given item type
pub fn register_item_type(self, did: DefId, scheme: TypeScheme<'gcx>) {
self.tcache.borrow_mut().insert(did, scheme.ty);
self.generics.borrow_mut().insert(did, scheme.generics);
}
// If the given item is in an external crate, looks up its type and adds it to
// the type cache. Returns the type parameters and type.
pub fn lookup_item_type(self, did: DefId) -> TypeScheme<'gcx> {
let ty = lookup_locally_or_in_crate_store(
"tcache", did, &self.tcache,
|| self.sess.cstore.item_type(self.global_tcx(), did));
TypeScheme {
ty: ty,
generics: self.lookup_generics(did)
}
}
pub fn opt_lookup_item_type(self, did: DefId) -> Option<TypeScheme<'gcx>> {
if did.krate != LOCAL_CRATE {
return Some(self.lookup_item_type(did));
}
if let Some(ty) = self.tcache.borrow().get(&did).cloned() {
Some(TypeScheme {
ty: ty,
generics: self.lookup_generics(did)
})
} else {
None
}
pub fn item_type(self, did: DefId) -> Ty<'gcx> {
lookup_locally_or_in_crate_store(
"item_types", did, &self.item_types,
|| self.sess.cstore.item_type(self.global_tcx(), did))
}
/// Given the did of a trait, returns its canonical trait ref.
@ -2411,21 +2353,21 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
/// Given the did of an item, returns its generics.
pub fn lookup_generics(self, did: DefId) -> &'gcx Generics<'gcx> {
pub fn item_generics(self, did: DefId) -> &'gcx Generics<'gcx> {
lookup_locally_or_in_crate_store(
"generics", did, &self.generics,
|| self.alloc_generics(self.sess.cstore.item_generics(self.global_tcx(), did)))
}
/// Given the did of an item, returns its full set of predicates.
pub fn lookup_predicates(self, did: DefId) -> GenericPredicates<'gcx> {
pub fn item_predicates(self, did: DefId) -> GenericPredicates<'gcx> {
lookup_locally_or_in_crate_store(
"predicates", did, &self.predicates,
|| self.sess.cstore.item_predicates(self.global_tcx(), did))
}
/// Given the did of a trait, returns its superpredicates.
pub fn lookup_super_predicates(self, did: DefId) -> GenericPredicates<'gcx> {
pub fn item_super_predicates(self, did: DefId) -> GenericPredicates<'gcx> {
lookup_locally_or_in_crate_store(
"super_predicates", did, &self.super_predicates,
|| self.sess.cstore.item_super_predicates(self.global_tcx(), did))
@ -2718,7 +2660,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
//
let tcx = self.global_tcx();
let generic_predicates = tcx.lookup_predicates(def_id);
let generic_predicates = tcx.item_predicates(def_id);
let bounds = generic_predicates.instantiate(tcx, free_substs);
let bounds = tcx.liberate_late_bound_regions(free_id_outlive, &ty::Binder(bounds));
let predicates = bounds.predicates;

View File

@ -164,7 +164,7 @@ pub enum TypeVariants<'tcx> {
/// Anonymized (`impl Trait`) type found in a return type.
/// The DefId comes from the `impl Trait` ast::Ty node, and the
/// substitutions are for the generics of the function in question.
/// After typeck, the concrete type can be found in the `tcache` map.
/// After typeck, the concrete type can be found in the `types` map.
TyAnon(DefId, &'tcx Substs<'tcx>),
/// A type parameter; for example, `T` in `fn f<T>(x: T) {}
@ -556,7 +556,7 @@ pub struct DebruijnIndex {
///
/// These are regions that are stored behind a binder and must be substituted
/// with some concrete region before being used. There are 2 kind of
/// bound regions: early-bound, which are bound in a TypeScheme/TraitDef,
/// bound regions: early-bound, which are bound in an item's Generics,
/// and are substituted by a Substs, and late-bound, which are part of
/// higher-ranked types (e.g. `for<'a> fn(&'a ())`) and are substituted by
/// the likes of `liberate_late_bound_regions`. The distinction exists

View File

@ -177,7 +177,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
-> &'tcx Substs<'tcx>
where FR: FnMut(&ty::RegionParameterDef, &[Kind<'tcx>]) -> &'tcx ty::Region,
FT: FnMut(&ty::TypeParameterDef<'tcx>, &[Kind<'tcx>]) -> Ty<'tcx> {
let defs = tcx.lookup_generics(def_id);
let defs = tcx.item_generics(def_id);
let mut substs = Vec::with_capacity(defs.count());
Substs::fill_item(&mut substs, tcx, defs, &mut mk_region, &mut mk_type);
tcx.intern_substs(&substs)
@ -192,7 +192,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
FT: FnMut(&ty::TypeParameterDef<'tcx>, &[Kind<'tcx>]) -> Ty<'tcx> {
if let Some(def_id) = defs.parent {
let parent_defs = tcx.lookup_generics(def_id);
let parent_defs = tcx.item_generics(def_id);
Substs::fill_item(substs, tcx, parent_defs, mk_region, mk_type);
}
@ -271,7 +271,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
source_ancestor: DefId,
target_substs: &Substs<'tcx>)
-> &'tcx Substs<'tcx> {
let defs = tcx.lookup_generics(source_ancestor);
let defs = tcx.item_generics(source_ancestor);
tcx.mk_substs(target_substs.iter().chain(&self[defs.own_count()..]).cloned())
}
}
@ -519,7 +519,7 @@ impl<'a, 'gcx, 'tcx> ty::TraitRef<'tcx> {
trait_id: DefId,
substs: &Substs<'tcx>)
-> ty::TraitRef<'tcx> {
let defs = tcx.lookup_generics(trait_id);
let defs = tcx.item_generics(trait_id);
ty::TraitRef {
def_id: trait_id,

View File

@ -18,7 +18,7 @@ use std::cell::{Cell, RefCell};
use hir;
use util::nodemap::FxHashMap;
/// As `TypeScheme` but for a trait ref.
/// A trait's definition with type information.
pub struct TraitDef<'tcx> {
pub unsafety: hir::Unsafety,

View File

@ -446,7 +446,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
-> Vec<traits::PredicateObligation<'tcx>>
{
let predicates =
self.infcx.tcx.lookup_predicates(def_id)
self.infcx.tcx.item_predicates(def_id)
.instantiate(self.infcx.tcx, substs);
let cause = self.cause(traits::ItemObligation(def_id));
predicates.predicates

View File

@ -105,7 +105,7 @@ pub fn parameterized(f: &mut fmt::Formatter,
}
}
}
let mut generics = tcx.lookup_generics(item_def_id);
let mut generics = tcx.item_generics(item_def_id);
let mut path_def_id = did;
verbose = tcx.sess.verbose();
has_self = generics.has_self;
@ -115,7 +115,7 @@ pub fn parameterized(f: &mut fmt::Formatter,
// Methods.
assert!(is_value_path);
child_types = generics.types.len();
generics = tcx.lookup_generics(def_id);
generics = tcx.item_generics(def_id);
num_regions = generics.regions.len();
num_types = generics.types.len();
@ -865,7 +865,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
TyAdt(def, substs) => {
ty::tls::with(|tcx| {
if def.did.is_local() &&
!tcx.tcache.borrow().contains_key(&def.did) {
!tcx.item_types.borrow().contains_key(&def.did) {
write!(f, "{}<..>", tcx.item_path_str(def.did))
} else {
parameterized(f, substs, def.did, &[])
@ -878,7 +878,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
ty::tls::with(|tcx| {
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
// by looking up the projections associated with the def_id.
let item_predicates = tcx.lookup_predicates(def_id);
let item_predicates = tcx.item_predicates(def_id);
let substs = tcx.lift(&substs).unwrap_or_else(|| {
tcx.intern_substs(&[])
});

View File

@ -858,7 +858,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
let free_func = tcx.lang_items.require(lang_items::BoxFreeFnLangItem)
.unwrap_or_else(|e| tcx.sess.fatal(&e));
let substs = tcx.mk_substs(iter::once(Kind::from(ty)));
let fty = tcx.lookup_item_type(free_func).ty.subst(tcx, substs);
let fty = tcx.item_type(free_func).subst(tcx, substs);
self.patch.new_block(BasicBlockData {
statements: statements,

View File

@ -118,9 +118,10 @@ impl LateLintPass for BoxPointers {
hir::ItemEnum(..) |
hir::ItemStruct(..) |
hir::ItemUnion(..) => {
self.check_heap_type(cx, it.span, cx.tcx.tables().node_id_to_type(it.id))
let def_id = cx.tcx.map.local_def_id(it.id);
self.check_heap_type(cx, it.span, cx.tcx.item_type(def_id))
}
_ => (),
_ => ()
}
// If it's a struct, we also have to check the fields' types
@ -128,9 +129,9 @@ impl LateLintPass for BoxPointers {
hir::ItemStruct(ref struct_def, _) |
hir::ItemUnion(ref struct_def, _) => {
for struct_field in struct_def.fields() {
self.check_heap_type(cx,
struct_field.span,
cx.tcx.tables().node_id_to_type(struct_field.id));
let def_id = cx.tcx.map.local_def_id(struct_field.id);
self.check_heap_type(cx, struct_field.span,
cx.tcx.item_type(def_id));
}
}
_ => (),
@ -585,11 +586,9 @@ impl LateLintPass for MissingDebugImplementations {
let debug_def = cx.tcx.lookup_trait_def(debug);
let mut impls = NodeSet();
debug_def.for_each_impl(cx.tcx, |d| {
if let Some(n) = cx.tcx.map.as_local_node_id(d) {
if let Some(ty_def) = cx.tcx.tables().node_id_to_type(n).ty_to_def_id() {
if let Some(node_id) = cx.tcx.map.as_local_node_id(ty_def) {
impls.insert(node_id);
}
if let Some(ty_def) = cx.tcx.item_type(d).ty_to_def_id() {
if let Some(node_id) = cx.tcx.map.as_local_node_id(ty_def) {
impls.insert(node_id);
}
}
});
@ -1225,7 +1224,7 @@ impl LateLintPass for MutableTransmutes {
}
fn def_id_is_transmute(cx: &LateContext, def_id: DefId) -> bool {
match cx.tcx.lookup_item_type(def_id).ty.sty {
match cx.tcx.item_type(def_id).sty {
ty::TyFnDef(.., ref bfty) if bfty.abi == RustIntrinsic => (),
_ => return false,
}
@ -1282,7 +1281,7 @@ impl LateLintPass for UnionsWithDropFields {
if let hir::ItemUnion(ref vdata, _) = item.node {
let param_env = &ty::ParameterEnvironment::for_item(ctx.tcx, item.id);
for field in vdata.fields() {
let field_ty = ctx.tcx.tables().node_id_to_type(field.id);
let field_ty = ctx.tcx.item_type(ctx.tcx.map.local_def_id(field.id));
if ctx.tcx.type_needs_drop_given_env(field_ty, param_env) {
ctx.span_lint(UNIONS_WITH_DROP_FIELDS,
field.span,

View File

@ -675,8 +675,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
fn check_foreign_fn(&mut self, id: ast::NodeId, decl: &hir::FnDecl) {
let def_id = self.cx.tcx.map.local_def_id(id);
let scheme = self.cx.tcx.lookup_item_type(def_id);
let sig = scheme.ty.fn_sig();
let sig = self.cx.tcx.item_type(def_id).fn_sig();
let sig = self.cx.tcx.erase_late_bound_regions(&sig);
for (&input_ty, input_hir) in sig.inputs.iter().zip(&decl.inputs) {
@ -693,8 +692,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
fn check_foreign_static(&mut self, id: ast::NodeId, span: Span) {
let def_id = self.cx.tcx.map.local_def_id(id);
let scheme = self.cx.tcx.lookup_item_type(def_id);
self.check_type_for_ffi_and_report_errors(span, scheme.ty);
let ty = self.cx.tcx.item_type(def_id);
self.check_type_for_ffi_and_report_errors(span, ty);
}
}
@ -740,11 +739,12 @@ impl LateLintPass for VariantSizeDifferences {
if let hir::ItemEnum(ref enum_definition, ref gens) = it.node {
if gens.ty_params.is_empty() {
// sizes only make sense for non-generic types
let t = cx.tcx.tables().node_id_to_type(it.id);
let t = cx.tcx.item_type(cx.tcx.map.local_def_id(it.id));
let layout = cx.tcx.infer_ctxt(None, None, Reveal::All).enter(|infcx| {
let ty = cx.tcx.erase_regions(&t);
ty.layout(&infcx)
.unwrap_or_else(|e| bug!("failed to get layout for `{}`: {}", t, e))
ty.layout(&infcx).unwrap_or_else(|e| {
bug!("failed to get layout for `{}`: {}", t, e)
})
});
if let Layout::General { ref variants, ref size, discr, .. } = *layout {

View File

@ -133,7 +133,10 @@ pub fn decode_inlined_item<'a, 'tcx>(cdata: &CrateMetadata,
&InlinedItem::ImplItem(_, ref ii) => ii.id,
};
let inlined_did = tcx.map.local_def_id(item_node_id);
tcx.register_item_type(inlined_did, tcx.lookup_item_type(orig_did));
let ty = tcx.item_type(orig_did);
let generics = tcx.item_generics(orig_did);
tcx.item_types.borrow_mut().insert(inlined_did, ty);
tcx.generics.borrow_mut().insert(inlined_did, generics);
for (id, entry) in ast.side_tables.decode((cdata, tcx, id_ranges)) {
match entry {
@ -141,7 +144,7 @@ pub fn decode_inlined_item<'a, 'tcx>(cdata: &CrateMetadata,
tcx.def_map.borrow_mut().insert(id, def::PathResolution::new(def));
}
TableEntry::NodeType(ty) => {
tcx.node_type_insert(id, ty);
tcx.tables.borrow_mut().node_types.insert(id, ty);
}
TableEntry::ItemSubsts(item_substs) => {
tcx.tables.borrow_mut().item_substs.insert(id, item_substs);

View File

@ -527,7 +527,7 @@ impl<'a, 'tcx> CrateMetadata {
ty::TraitDef::new(data.unsafety,
data.paren_sugar,
tcx.lookup_generics(self.local_def_id(item_id)),
tcx.item_generics(self.local_def_id(item_id)),
data.trait_ref.decode((self, tcx)),
self.def_path(item_id).unwrap().deterministic_hash(tcx))
}

View File

@ -246,7 +246,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
fn encode_item_type(&mut self, def_id: DefId) -> Lazy<Ty<'tcx>> {
let tcx = self.tcx;
self.lazy(&tcx.lookup_item_type(def_id).ty)
self.lazy(&tcx.item_type(def_id))
}
/// Encode data for the given variant of the given ADT. The
@ -444,12 +444,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
fn encode_generics(&mut self, def_id: DefId) -> Lazy<ty::Generics<'tcx>> {
let tcx = self.tcx;
self.lazy(tcx.lookup_generics(def_id))
self.lazy(tcx.item_generics(def_id))
}
fn encode_predicates(&mut self, def_id: DefId) -> Lazy<ty::GenericPredicates<'tcx>> {
let tcx = self.tcx;
self.lazy(&tcx.lookup_predicates(def_id))
self.lazy(&tcx.item_predicates(def_id))
}
fn encode_info_for_trait_item(&mut self, def_id: DefId) -> Entry<'tcx> {
@ -556,7 +556,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let (ast, mir) = if impl_item.kind == ty::AssociatedKind::Const {
(true, true)
} else if let hir::ImplItemKind::Method(ref sig, _) = ast_item.node {
let generics = self.tcx.lookup_generics(def_id);
let generics = self.tcx.item_generics(def_id);
let types = generics.parent_types as usize + generics.types.len();
let needs_inline = types > 0 || attr::requests_inline(&ast_item.attrs);
let is_const_fn = sig.constness == hir::Constness::Const;
@ -717,7 +717,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
paren_sugar: trait_def.paren_sugar,
has_default_impl: tcx.trait_has_default_impl(def_id),
trait_ref: self.lazy(&trait_def.trait_ref),
super_predicates: self.lazy(&tcx.lookup_super_predicates(def_id)),
super_predicates: self.lazy(&tcx.item_super_predicates(def_id)),
};
EntryKind::Trait(self.lazy(&data))

View File

@ -155,6 +155,7 @@ macro_rules! unpack {
pub fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
fn_id: ast::NodeId,
arguments: A,
abi: Abi,
return_ty: Ty<'gcx>,
ast_body: &'gcx hir::Expr)
-> (Mir<'tcx>, ScopeAuxiliaryVec)
@ -191,12 +192,9 @@ pub fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
assert_eq!(block, builder.return_block());
let mut spread_arg = None;
match tcx.tables().node_id_to_type(fn_id).sty {
ty::TyFnDef(_, _, f) if f.abi == Abi::RustCall => {
// RustCall pseudo-ABI untuples the last argument.
spread_arg = Some(Local::new(arguments.len()));
}
_ => {}
if abi == Abi::RustCall {
// RustCall pseudo-ABI untuples the last argument.
spread_arg = Some(Local::new(arguments.len()));
}
// Gather the upvars of a closure, if any.

View File

@ -806,7 +806,7 @@ fn build_free<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
TerminatorKind::Call {
func: Operand::Constant(Constant {
span: data.span,
ty: tcx.lookup_item_type(free_func).ty.subst(tcx, substs),
ty: tcx.item_type(free_func).subst(tcx, substs),
literal: Literal::Item {
def_id: free_func,
substs: substs

View File

@ -149,8 +149,8 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
let substs = self.tcx.mk_substs_trait(self_ty, params);
for item in self.tcx.associated_items(trait_def_id) {
if item.kind == ty::AssociatedKind::Method && item.name == method_name {
let method_ty = self.tcx.lookup_item_type(item.def_id);
let method_ty = method_ty.ty.subst(self.tcx, substs);
let method_ty = self.tcx.item_type(item.def_id);
let method_ty = method_ty.subst(self.tcx, substs);
return (method_ty, Literal::Item {
def_id: item.def_id,
substs: substs,

View File

@ -31,6 +31,7 @@ use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::subst::Substs;
use rustc::hir;
use rustc::hir::intravisit::{self, FnKind, Visitor};
use syntax::abi::Abi;
use syntax::ast;
use syntax_pos::Span;
@ -221,10 +222,11 @@ impl<'a, 'tcx> Visitor<'tcx> for BuildMir<'a, 'tcx> {
}
};
let implicit_argument = if let FnKind::Closure(..) = fk {
Some((closure_self_ty(self.tcx, id, body.id), None))
let (abi, implicit_argument) = if let FnKind::Closure(..) = fk {
(Abi::Rust, Some((closure_self_ty(self.tcx, id, body.id), None)))
} else {
None
let def_id = self.tcx.map.local_def_id(id);
(self.tcx.item_type(def_id).fn_abi(), None)
};
let explicit_arguments =
@ -237,7 +239,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BuildMir<'a, 'tcx> {
let arguments = implicit_argument.into_iter().chain(explicit_arguments);
self.cx(MirSource::Fn(id)).build(|cx| {
build::construct_fn(cx, id, arguments, fn_sig.output, body)
build::construct_fn(cx, id, arguments, abi, fn_sig.output, body)
});
intravisit::walk_fn(self, fk, decl, body, span, id);

View File

@ -127,7 +127,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
match *lvalue {
Lvalue::Local(index) => LvalueTy::Ty { ty: self.mir.local_decls[index].ty },
Lvalue::Static(def_id) =>
LvalueTy::Ty { ty: self.tcx().lookup_item_type(def_id).ty },
LvalueTy::Ty { ty: self.tcx().item_type(def_id) },
Lvalue::Projection(ref proj) => {
let base_ty = self.sanitize_lvalue(&proj.base, location);
if let LvalueTy::Ty { ty } = base_ty {

View File

@ -286,7 +286,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
scope: NodeId) -> Option<VariableData> {
if let Some(ident) = field.ident {
let qualname = format!("::{}::{}", self.tcx.node_path_str(scope), ident);
let typ = self.tcx.tables().node_types.get(&field.id).unwrap().to_string();
let def_id = self.tcx.map.local_def_id(field.id);
let typ = self.tcx.item_type(def_id).to_string();
let sub_span = self.span_utils.sub_span_before_token(field.span, token::Colon);
filter!(self.span_utils, sub_span, field.span, None);
Some(VariableData {

View File

@ -231,7 +231,7 @@ impl<'a, 'tcx> Instance<'tcx> {
match key.disambiguated_data.data {
DefPathData::TypeNs(_) |
DefPathData::ValueNs(_) => {
instance_ty = scx.tcx().lookup_item_type(ty_def_id);
instance_ty = scx.tcx().item_type(ty_def_id);
break;
}
_ => {
@ -248,7 +248,7 @@ impl<'a, 'tcx> Instance<'tcx> {
// Erase regions because they may not be deterministic when hashed
// and should not matter anyhow.
let instance_ty = scx.tcx().erase_regions(&instance_ty.ty);
let instance_ty = scx.tcx().erase_regions(&instance_ty);
let hash = get_symbol_hash(scx, &def_path, instance_ty, Some(substs));

View File

@ -1045,7 +1045,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
debug!("trans_instance(instance={:?})", instance);
let _icx = push_ctxt("trans_instance");
let fn_ty = ccx.tcx().lookup_item_type(instance.def).ty;
let fn_ty = ccx.tcx().item_type(instance.def);
let fn_ty = ccx.tcx().erase_regions(&fn_ty);
let fn_ty = monomorphize::apply_param_substs(ccx.shared(), instance.substs, &fn_ty);
@ -1068,7 +1068,7 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
attributes::inline(llfndecl, attributes::InlineAttr::Hint);
attributes::set_frame_pointer_elimination(ccx, llfndecl);
let ctor_ty = ccx.tcx().lookup_item_type(def_id).ty;
let ctor_ty = ccx.tcx().item_type(def_id);
let ctor_ty = monomorphize::apply_param_substs(ccx.shared(), substs, &ctor_ty);
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&ctor_ty.fn_sig());
@ -1514,7 +1514,7 @@ pub fn filter_reachable_ids(tcx: TyCtxt, reachable: NodeSet) -> NodeSet {
hir_map::NodeImplItem(&hir::ImplItem {
node: hir::ImplItemKind::Method(..), .. }) => {
let def_id = tcx.map.local_def_id(id);
let generics = tcx.lookup_generics(def_id);
let generics = tcx.item_generics(def_id);
let attributes = tcx.get_attrs(def_id);
(generics.parent_types == 0 && generics.types.is_empty()) &&
// Functions marked with #[inline] are only ever translated
@ -1719,7 +1719,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let applicable = match sess.cstore.describe_def(def_id) {
Some(Def::Static(..)) => true,
Some(Def::Fn(_)) => {
shared_ccx.tcx().lookup_generics(def_id).types.is_empty()
shared_ccx.tcx().item_generics(def_id).types.is_empty()
}
_ => false
};

View File

@ -246,7 +246,7 @@ fn def_ty<'a, 'tcx>(shared: &SharedCrateContext<'a, 'tcx>,
def_id: DefId,
substs: &'tcx Substs<'tcx>)
-> Ty<'tcx> {
let ty = shared.tcx().lookup_item_type(def_id).ty;
let ty = shared.tcx().item_type(def_id);
monomorphize::apply_param_substs(shared, substs, &ty)
}
@ -400,7 +400,7 @@ fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
let substs = tcx.normalize_associated_type(&substs);
let instance = Instance::new(def_id, substs);
let item_ty = ccx.tcx().lookup_item_type(def_id).ty;
let item_ty = ccx.tcx().item_type(def_id);
let fn_ty = monomorphize::apply_param_substs(ccx.shared(), substs, &item_ty);
if let Some(&llfn) = ccx.instances().borrow().get(&instance) {

View File

@ -337,7 +337,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(scx: &SharedCrateContext<'a, 'tcx>,
}
TransItem::Static(node_id) => {
let def_id = scx.tcx().map.local_def_id(node_id);
let ty = scx.tcx().lookup_item_type(def_id).ty;
let ty = scx.tcx().item_type(def_id);
let ty = glue::get_drop_glue_type(scx.tcx(), ty);
neighbors.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
@ -618,7 +618,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
fn can_result_in_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId)
-> bool {
match tcx.lookup_item_type(def_id).ty.sty {
match tcx.item_type(def_id).sty {
ty::TyFnDef(def_id, _, f) => {
// Some constructors also have type TyFnDef but they are
// always instantiated inline and don't result in
@ -1077,13 +1077,12 @@ impl<'b, 'a, 'v> hir_visit::Visitor<'v> for RootCollector<'b, 'a, 'v> {
hir::ItemStruct(_, ref generics) |
hir::ItemUnion(_, ref generics) => {
if !generics.is_parameterized() {
let ty = self.scx.tcx().tables().node_types[&item.id];
if self.mode == TransItemCollectionMode::Eager {
let def_id = self.scx.tcx().map.local_def_id(item.id);
debug!("RootCollector: ADT drop-glue for {}",
def_id_to_string(self.scx.tcx(),
self.scx.tcx().map.local_def_id(item.id)));
def_id_to_string(self.scx.tcx(), def_id));
let ty = self.scx.tcx().item_type(def_id);
let ty = glue::get_drop_glue_type(self.scx.tcx(), ty);
self.output.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
}
@ -1182,7 +1181,7 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(scx: &SharedCrateContext<'a, '
continue;
}
if !tcx.lookup_generics(method.def_id).types.is_empty() {
if !tcx.item_generics(method.def_id).types.is_empty() {
continue;
}
@ -1201,7 +1200,7 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(scx: &SharedCrateContext<'a, '
callee_substs,
&impl_data);
let predicates = tcx.lookup_predicates(def_id).predicates
let predicates = tcx.item_predicates(def_id).predicates
.subst(tcx, substs);
if !traits::normalize_and_test_predicates(tcx, predicates) {
continue;

View File

@ -84,7 +84,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
return g;
}
let ty = ccx.tcx().lookup_item_type(def_id).ty;
let ty = ccx.tcx().item_type(def_id);
let g = if let Some(id) = ccx.tcx().map.as_local_node_id(def_id) {
let llty = type_of::type_of(ccx, ty);
@ -226,7 +226,7 @@ pub fn trans_static(ccx: &CrateContext,
v
};
let ty = ccx.tcx().lookup_item_type(def_id).ty;
let ty = ccx.tcx().item_type(def_id);
let llty = type_of::type_of(ccx, ty);
let g = if val_llty == llty {
g

View File

@ -1765,7 +1765,7 @@ pub fn create_global_var_metadata(cx: &CrateContext,
};
let is_local_to_unit = is_node_local_to_unit(cx, node_id);
let variable_type = tcx.erase_regions(&tcx.tables().node_id_to_type(node_id));
let variable_type = tcx.erase_regions(&tcx.item_type(node_def_id));
let type_metadata = type_metadata(cx, variable_type, span);
let var_name = tcx.item_name(node_def_id).to_string();
let linkage_name = mangled_name_of_item(cx, node_def_id, "");

View File

@ -259,7 +259,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
// Get_template_parameters() will append a `<...>` clause to the function
// name if necessary.
let generics = cx.tcx().lookup_generics(fn_def_id);
let generics = cx.tcx().item_generics(fn_def_id);
let template_parameters = get_template_parameters(cx,
&generics,
instance.substs,
@ -397,7 +397,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
generics: &ty::Generics<'tcx>)
-> Vec<ast::Name> {
let mut names = generics.parent.map_or(vec![], |def_id| {
get_type_parameter_names(cx, cx.tcx().lookup_generics(def_id))
get_type_parameter_names(cx, cx.tcx().item_generics(def_id))
});
names.extend(generics.types.iter().map(|param| param.name));
names
@ -412,7 +412,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let self_type = cx.tcx().impl_of_method(instance.def).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().lookup_item_type(impl_def_id).ty;
let impl_self_ty = cx.tcx().item_type(impl_def_id);
let impl_self_ty = cx.tcx().erase_regions(&impl_self_ty);
let impl_self_ty = monomorphize::apply_param_substs(cx.shared(),
instance.substs,

View File

@ -495,7 +495,7 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(scx: &SharedCrateContext<'a, 't
if let Some(impl_def_id) = tcx.impl_of_method(instance.def) {
// This is a method within an inherent impl, find out what the
// self-type is:
let impl_self_ty = tcx.lookup_item_type(impl_def_id).ty;
let impl_self_ty = tcx.item_type(impl_def_id);
let impl_self_ty = tcx.erase_regions(&impl_self_ty);
let impl_self_ty = monomorphize::apply_param_substs(scx,
instance.substs,

View File

@ -131,7 +131,7 @@ impl<'a, 'tcx> TransItem<'tcx> {
linkage: llvm::Linkage,
symbol_name: &str) {
let def_id = ccx.tcx().map.local_def_id(node_id);
let ty = ccx.tcx().lookup_item_type(def_id).ty;
let ty = ccx.tcx().item_type(def_id);
let llty = type_of::type_of(ccx, ty);
let g = declare::define_global(ccx, symbol_name, llty).unwrap_or_else(|| {
@ -153,7 +153,7 @@ impl<'a, 'tcx> TransItem<'tcx> {
assert!(!instance.substs.needs_infer() &&
!instance.substs.has_param_types());
let item_ty = ccx.tcx().lookup_item_type(instance.def).ty;
let item_ty = ccx.tcx().item_type(instance.def);
let item_ty = ccx.tcx().erase_regions(&item_ty);
let mono_ty = monomorphize::apply_param_substs(ccx.shared(), instance.substs, &item_ty);

View File

@ -16,12 +16,12 @@
//! somewhat differently during the collect and check phases,
//! particularly with respect to looking up the types of top-level
//! items. In the collect phase, the crate context is used as the
//! `AstConv` instance; in this phase, the `get_item_type_scheme()`
//! function triggers a recursive call to `type_scheme_of_item()`
//! `AstConv` instance; in this phase, the `get_item_type()`
//! function triggers a recursive call to `type_of_item()`
//! (note that `ast_ty_to_ty()` will detect recursive types and report
//! an error). In the check phase, when the FnCtxt is used as the
//! `AstConv`, `get_item_type_scheme()` just looks up the item type in
//! `tcx.tcache` (using `ty::lookup_item_type`).
//! `AstConv`, `get_item_type()` just looks up the item type in
//! `tcx.types` (using `TyCtxt::item_type`).
//!
//! The `RegionScope` trait controls what happens when the user does
//! not specify a region in some location where a region is required
@ -85,11 +85,8 @@ pub trait AstConv<'gcx, 'tcx> {
fn get_generics(&self, span: Span, id: DefId)
-> Result<&'tcx ty::Generics<'tcx>, ErrorReported>;
/// Identify the type scheme for an item with a type, like a type
/// alias, fn, or struct. This allows you to figure out the set of
/// type parameters defined on the item.
fn get_item_type_scheme(&self, span: Span, id: DefId)
-> Result<ty::TypeScheme<'tcx>, ErrorReported>;
/// Identify the type for an item, like a type alias, fn, or struct.
fn get_item_type(&self, span: Span, id: DefId) -> Result<Ty<'tcx>, ErrorReported>;
/// Returns the `TraitDef` for a given trait. This allows you to
/// figure out the set of type parameters defined on the trait.
@ -938,8 +935,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
-> Ty<'tcx>
{
let tcx = self.tcx();
let decl_ty = match self.get_item_type_scheme(span, did) {
Ok(type_scheme) => type_scheme.ty,
let decl_ty = match self.get_item_type(span, did) {
Ok(ty) => ty,
Err(ErrorReported) => {
return tcx.types.err;
}
@ -1521,8 +1518,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
// Self in impl (we know the concrete type).
tcx.prohibit_type_params(base_segments);
let impl_id = tcx.map.as_local_node_id(def_id).unwrap();
let ty = tcx.tables().node_id_to_type(impl_id);
let ty = tcx.item_type(def_id);
if let Some(free_substs) = self.get_free_substs() {
ty.subst(tcx, free_substs)
} else {

View File

@ -174,10 +174,10 @@ fn compare_predicate_entailment<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
debug!("compare_impl_method: trait_to_skol_substs={:?}",
trait_to_skol_substs);
let impl_m_generics = tcx.lookup_generics(impl_m.def_id);
let trait_m_generics = tcx.lookup_generics(trait_m.def_id);
let impl_m_predicates = tcx.lookup_predicates(impl_m.def_id);
let trait_m_predicates = tcx.lookup_predicates(trait_m.def_id);
let impl_m_generics = tcx.item_generics(impl_m.def_id);
let trait_m_generics = tcx.item_generics(trait_m.def_id);
let impl_m_predicates = tcx.item_predicates(impl_m.def_id);
let trait_m_predicates = tcx.item_predicates(trait_m.def_id);
// Check region bounds.
check_region_bounds_on_impl_method(ccx,
@ -193,7 +193,7 @@ fn compare_predicate_entailment<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
// environment. We can't just use `impl_env.caller_bounds`,
// however, because we want to replace all late-bound regions with
// region variables.
let impl_predicates = tcx.lookup_predicates(impl_m_predicates.parent.unwrap());
let impl_predicates = tcx.item_predicates(impl_m_predicates.parent.unwrap());
let mut hybrid_preds = impl_predicates.instantiate(tcx, impl_to_skol_substs);
debug!("compare_impl_method: impl_bounds={:?}", hybrid_preds);
@ -269,7 +269,7 @@ fn compare_predicate_entailment<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
let origin = TypeOrigin::MethodCompatCheck(impl_m_span);
let m_fty = |method: &ty::AssociatedItem| {
match tcx.lookup_item_type(method.def_id).ty.sty {
match tcx.item_type(method.def_id).sty {
ty::TyFnDef(_, _, f) => f,
_ => bug!()
}
@ -542,7 +542,7 @@ fn compare_self_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
ty::ImplContainer(_) => impl_trait_ref.self_ty(),
ty::TraitContainer(_) => tcx.mk_self_type()
};
let method_ty = tcx.lookup_item_type(method.def_id).ty;
let method_ty = tcx.item_type(method.def_id);
let self_arg_ty = *method_ty.fn_sig().input(0).skip_binder();
match ExplicitSelf::determine(untransformed_self_ty, self_arg_ty) {
ExplicitSelf::ByValue => "self".to_string(),
@ -601,8 +601,8 @@ fn compare_number_of_generics<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
trait_item_span: Option<Span>)
-> Result<(), ErrorReported> {
let tcx = ccx.tcx;
let impl_m_generics = tcx.lookup_generics(impl_m.def_id);
let trait_m_generics = tcx.lookup_generics(trait_m.def_id);
let impl_m_generics = tcx.item_generics(impl_m.def_id);
let trait_m_generics = tcx.item_generics(trait_m.def_id);
let num_impl_m_type_params = impl_m_generics.types.len();
let num_trait_m_type_params = trait_m_generics.types.len();
if num_impl_m_type_params != num_trait_m_type_params {
@ -672,7 +672,7 @@ fn compare_number_of_method_arguments<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
-> Result<(), ErrorReported> {
let tcx = ccx.tcx;
let m_fty = |method: &ty::AssociatedItem| {
match tcx.lookup_item_type(method.def_id).ty.sty {
match tcx.item_type(method.def_id).sty {
ty::TyFnDef(_, _, f) => f,
_ => bug!()
}
@ -785,8 +785,8 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
trait_to_skol_substs);
// Compute skolemized form of impl and trait const tys.
let impl_ty = tcx.lookup_item_type(impl_c.def_id).ty.subst(tcx, impl_to_skol_substs);
let trait_ty = tcx.lookup_item_type(trait_c.def_id).ty.subst(tcx, trait_to_skol_substs);
let impl_ty = tcx.item_type(impl_c.def_id).subst(tcx, impl_to_skol_substs);
let trait_ty = tcx.item_type(trait_c.def_id).subst(tcx, trait_to_skol_substs);
let mut origin = TypeOrigin::Misc(impl_c_span);
let err = infcx.commit_if_ok(|_| {

View File

@ -41,8 +41,8 @@ use syntax_pos::{self, Span};
/// cannot do `struct S<T>; impl<T:Clone> Drop for S<T> { ... }`).
///
pub fn check_drop_impl(ccx: &CrateCtxt, drop_impl_did: DefId) -> Result<(), ()> {
let dtor_self_type = ccx.tcx.lookup_item_type(drop_impl_did).ty;
let dtor_predicates = ccx.tcx.lookup_predicates(drop_impl_did);
let dtor_self_type = ccx.tcx.item_type(drop_impl_did);
let dtor_predicates = ccx.tcx.item_predicates(drop_impl_did);
match dtor_self_type.sty {
ty::TyAdt(adt_def, self_to_impl_substs) => {
ensure_drop_params_and_item_params_correspond(ccx,
@ -85,7 +85,7 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>(
let tcx = infcx.tcx;
let mut fulfillment_cx = traits::FulfillmentContext::new();
let named_type = tcx.lookup_item_type(self_type_did).ty;
let named_type = tcx.item_type(self_type_did);
let named_type = named_type.subst(tcx, &infcx.parameter_environment.free_substs);
let drop_impl_span = tcx.map.def_id_span(drop_impl_did, syntax_pos::DUMMY_SP);
@ -177,7 +177,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>(
// We can assume the predicates attached to struct/enum definition
// hold.
let generic_assumptions = tcx.lookup_predicates(self_type_did);
let generic_assumptions = tcx.item_predicates(self_type_did);
let assumptions_in_impl_context = generic_assumptions.instantiate(tcx, &self_to_impl_substs);
let assumptions_in_impl_context = assumptions_in_impl_context.predicates;
@ -570,30 +570,30 @@ fn has_dtor_of_interest<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
// Constructs new Ty just like the type defined by `adt_def` coupled
// with `substs`, except each type and lifetime parameter marked as
// `#[may_dangle]` in the Drop impl (identified by `impl_id`) is
// `#[may_dangle]` in the Drop impl (identified by `impl_def_id`) is
// respectively mapped to `()` or `'static`.
//
// For example: If the `adt_def` maps to:
//
// enum Foo<'a, X, Y> { ... }
//
// and the `impl_id` maps to:
// and the `impl_def_id` maps to:
//
// impl<#[may_dangle] 'a, X, #[may_dangle] Y> Drop for Foo<'a, X, Y> { ... }
//
// then revises input: `Foo<'r,i64,&'r i64>` to: `Foo<'static,i64,()>`
fn revise_self_ty<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
adt_def: ty::AdtDef<'tcx>,
impl_id: DefId,
impl_def_id: DefId,
substs: &Substs<'tcx>)
-> Ty<'tcx> {
// Get generics for `impl Drop` to query for `#[may_dangle]` attr.
let impl_bindings = tcx.lookup_generics(impl_id);
let impl_bindings = tcx.item_generics(impl_def_id);
// Get Substs attached to Self on `impl Drop`; process in parallel
// with `substs`, replacing dangling entries as appropriate.
let self_substs = {
let impl_self_ty: Ty<'tcx> = tcx.lookup_item_type(impl_id).ty;
let impl_self_ty: Ty<'tcx> = tcx.item_type(impl_def_id);
if let ty::TyAdt(self_adt_def, self_substs) = impl_self_ty.sty {
assert_eq!(adt_def, self_adt_def);
self_substs
@ -648,5 +648,5 @@ fn revise_self_ty<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
t
});
return tcx.mk_adt(adt_def, &substs);
tcx.mk_adt(adt_def, &substs)
}

View File

@ -34,7 +34,6 @@ fn equate_intrinsic_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
output: Ty<'tcx>) {
let tcx = ccx.tcx;
let def_id = tcx.map.local_def_id(it.id);
let i_ty = tcx.lookup_item_type(def_id);
let substs = Substs::for_item(tcx, def_id,
|_, _| tcx.mk_region(ty::ReErased),
@ -49,7 +48,7 @@ fn equate_intrinsic_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
variadic: false,
}),
}));
let i_n_tps = i_ty.generics.types.len();
let i_n_tps = tcx.item_generics(def_id).types.len();
if i_n_tps != n_tps {
let span = match it.node {
hir::ForeignItemFn(_, ref generics) => generics.span,
@ -65,7 +64,7 @@ fn equate_intrinsic_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
} else {
require_same_types(ccx,
TypeOrigin::IntrinsicType(it.span),
i_ty.ty,
tcx.item_type(def_id),
fty);
}
}
@ -330,8 +329,8 @@ pub fn check_platform_intrinsic_type(ccx: &CrateCtxt,
};
let tcx = ccx.tcx;
let i_ty = tcx.lookup_item_type(tcx.map.local_def_id(it.id));
let i_n_tps = i_ty.generics.types.len();
let def_id = tcx.map.local_def_id(it.id);
let i_n_tps = tcx.item_generics(def_id).types.len();
let name = it.name.as_str();
let (n_tps, inputs, output) = match &*name {
@ -374,7 +373,8 @@ pub fn check_platform_intrinsic_type(ccx: &CrateCtxt,
let mut structural_to_nomimal = FxHashMap();
let sig = tcx.no_late_bound_regions(i_ty.ty.fn_sig()).unwrap();
let sig = tcx.item_type(def_id).fn_sig();
let sig = tcx.no_late_bound_regions(sig).unwrap();
if intr.inputs.len() != sig.inputs.len() {
span_err!(tcx.sess, it.span, E0444,
"platform-specific intrinsic has invalid number of \

View File

@ -276,7 +276,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
// If they were not explicitly supplied, just construct fresh
// variables.
let num_supplied_types = supplied_method_types.len();
let method_generics = self.tcx.lookup_generics(pick.item.def_id);
let method_generics = self.tcx.item_generics(pick.item.def_id);
let num_method_types = method_generics.types.len();
if num_supplied_types > 0 && num_supplied_types != num_method_types {
@ -359,14 +359,14 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
// type/early-bound-regions substitutions performed. There can
// be no late-bound regions appearing here.
let def_id = pick.item.def_id;
let method_predicates = self.tcx.lookup_predicates(def_id)
let method_predicates = self.tcx.item_predicates(def_id)
.instantiate(self.tcx, all_substs);
let method_predicates = self.normalize_associated_types_in(self.span,
&method_predicates);
debug!("method_predicates after subst = {:?}", method_predicates);
let fty = match self.tcx.lookup_item_type(def_id).ty.sty {
let fty = match self.tcx.item_type(def_id).sty {
ty::TyFnDef(_, _, f) => f,
_ => bug!()
};

View File

@ -230,7 +230,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let tcx = self.tcx;
let method_item = self.associated_item(trait_def_id, m_name).unwrap();
let def_id = method_item.def_id;
let generics = tcx.lookup_generics(def_id);
let generics = tcx.item_generics(def_id);
assert_eq!(generics.types.len(), 0);
assert_eq!(generics.regions.len(), 0);
@ -242,7 +242,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// NB: Instantiate late-bound regions first so that
// `instantiate_type_scheme` can normalize associated types that
// may reference those regions.
let original_method_ty = tcx.lookup_item_type(def_id).ty;
let original_method_ty = tcx.item_type(def_id);
let fty = match original_method_ty.sty {
ty::TyFnDef(_, _, f) => f,
_ => bug!()

View File

@ -672,9 +672,9 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
}
};
let impl_type = self.tcx.lookup_item_type(impl_def_id);
let impl_type = self.tcx.item_type(impl_def_id);
let impl_simplified_type =
match ty::fast_reject::simplify_type(self.tcx, impl_type.ty, false) {
match ty::fast_reject::simplify_type(self.tcx, impl_type, false) {
Some(simplified_type) => simplified_type,
None => {
return true;
@ -771,7 +771,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
def_id,
substs);
let trait_predicates = self.tcx.lookup_predicates(def_id);
let trait_predicates = self.tcx.item_predicates(def_id);
let bounds = trait_predicates.instantiate(self.tcx, substs);
let predicates = bounds.predicates;
debug!("assemble_projection_candidates: predicates={:?}",
@ -1070,7 +1070,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
let cause = traits::ObligationCause::misc(self.span, self.body_id);
// Check whether the impl imposes obligations we have to worry about.
let impl_bounds = self.tcx.lookup_predicates(impl_def_id);
let impl_bounds = self.tcx.item_predicates(impl_def_id);
let impl_bounds = impl_bounds.instantiate(self.tcx, substs);
let traits::Normalized { value: impl_bounds, obligations: norm_obligations } =
traits::normalize(selcx, cause.clone(), &impl_bounds);
@ -1171,7 +1171,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
impl_ty: Ty<'tcx>,
substs: &Substs<'tcx>)
-> Ty<'tcx> {
let self_ty = self.tcx.lookup_item_type(method).ty.fn_sig().input(0);
let self_ty = self.tcx.item_type(method).fn_sig().input(0);
debug!("xform_self_ty(impl_ty={:?}, self_ty={:?}, substs={:?})",
impl_ty,
self_ty,
@ -1184,7 +1184,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
// are given do not include type/lifetime parameters for the
// method yet. So create fresh variables here for those too,
// if there are any.
let generics = self.tcx.lookup_generics(method);
let generics = self.tcx.item_generics(method);
assert_eq!(substs.types().count(), generics.parent_types as usize);
assert_eq!(substs.regions().count(), generics.parent_regions as usize);
@ -1218,7 +1218,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
/// Get the type of an impl and generate substitutions with placeholders.
fn impl_ty_and_substs(&self, impl_def_id: DefId) -> (Ty<'tcx>, &'tcx Substs<'tcx>) {
let impl_ty = self.tcx.lookup_item_type(impl_def_id).ty;
let impl_ty = self.tcx.item_type(impl_def_id);
let substs = Substs::for_item(self.tcx,
impl_def_id,

View File

@ -598,7 +598,7 @@ fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
body: &'tcx hir::Expr,
fn_id: ast::NodeId,
span: Span) {
let raw_fty = ccx.tcx.lookup_item_type(ccx.tcx.map.local_def_id(fn_id)).ty;
let raw_fty = ccx.tcx.item_type(ccx.tcx.map.local_def_id(fn_id));
let fn_ty = match raw_fty.sty {
ty::TyFnDef(.., f) => f,
_ => span_bug!(body.span, "check_bare_fn: function type expected")
@ -781,15 +781,16 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
}
fn check_struct(ccx: &CrateCtxt, id: ast::NodeId, span: Span) {
check_representable(ccx.tcx, span, id);
let def_id = ccx.tcx.map.local_def_id(id);
check_representable(ccx.tcx, span, def_id);
if ccx.tcx.lookup_simd(ccx.tcx.map.local_def_id(id)) {
check_simd(ccx.tcx, span, id);
if ccx.tcx.lookup_simd(def_id) {
check_simd(ccx.tcx, span, def_id);
}
}
fn check_union(ccx: &CrateCtxt, id: ast::NodeId, span: Span) {
check_representable(ccx.tcx, span, id);
check_representable(ccx.tcx, span, ccx.tcx.map.local_def_id(id));
}
pub fn check_item_type<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) {
@ -832,7 +833,8 @@ pub fn check_item_type<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) {
check_union(ccx, it.id, it.span);
}
hir::ItemTy(_, ref generics) => {
let pty_ty = ccx.tcx.tables().node_id_to_type(it.id);
let def_id = ccx.tcx.map.local_def_id(it.id);
let pty_ty = ccx.tcx.item_type(def_id);
check_bounds_are_used(ccx, generics, pty_ty);
}
hir::ItemForeignMod(ref m) => {
@ -848,8 +850,8 @@ pub fn check_item_type<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) {
}
} else {
for item in &m.items {
let pty = ccx.tcx.lookup_item_type(ccx.tcx.map.local_def_id(item.id));
if !pty.generics.types.is_empty() {
let generics = ccx.tcx.item_generics(ccx.tcx.map.local_def_id(item.id));
if !generics.types.is_empty() {
let mut err = struct_span_err!(ccx.tcx.sess, item.span, E0044,
"foreign items may not have type parameters");
span_help!(&mut err, item.span,
@ -918,7 +920,7 @@ pub fn check_item_body<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) {
fn check_on_unimplemented<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
def_id: DefId,
item: &hir::Item) {
let generics = ccx.tcx.lookup_generics(def_id);
let generics = ccx.tcx.item_generics(def_id);
if let Some(ref attr) = item.attrs.iter().find(|a| {
a.check_name("rustc_on_unimplemented")
}) {
@ -1144,12 +1146,11 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
let signature = |item: &ty::AssociatedItem| {
match item.kind {
ty::AssociatedKind::Method => {
format!("{}", tcx.lookup_item_type(item.def_id).ty.fn_sig().0)
format!("{}", tcx.item_type(item.def_id).fn_sig().0)
}
ty::AssociatedKind::Type => format!("type {};", item.name.to_string()),
ty::AssociatedKind::Const => {
format!("const {}: {:?};", item.name.to_string(),
tcx.lookup_item_type(item.def_id).ty)
format!("const {}: {:?};", item.name.to_string(), tcx.item_type(item.def_id))
}
}
};
@ -1219,7 +1220,7 @@ fn check_const_with_type<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>,
fn check_const<'a, 'tcx>(ccx: &CrateCtxt<'a,'tcx>,
expr: &'tcx hir::Expr,
id: ast::NodeId) {
let decl_ty = ccx.tcx.lookup_item_type(ccx.tcx.map.local_def_id(id)).ty;
let decl_ty = ccx.tcx.item_type(ccx.tcx.map.local_def_id(id));
check_const_with_type(ccx, expr, decl_ty, id);
}
@ -1228,9 +1229,9 @@ fn check_const<'a, 'tcx>(ccx: &CrateCtxt<'a,'tcx>,
/// pointer, which would mean their size is unbounded.
fn check_representable<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
sp: Span,
item_id: ast::NodeId)
item_def_id: DefId)
-> bool {
let rty = tcx.tables().node_id_to_type(item_id);
let rty = tcx.item_type(item_def_id);
// Check that it is possible to represent this type. This call identifies
// (1) types that contain themselves and (2) types that contain a different
@ -1239,7 +1240,6 @@ fn check_representable<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// caught by case 1.
match rty.is_representable(tcx, sp) {
Representability::SelfRecursive => {
let item_def_id = tcx.map.local_def_id(item_id);
tcx.recursive_type_with_infinite_size_error(item_def_id).emit();
return false
}
@ -1248,8 +1248,8 @@ fn check_representable<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
return true
}
pub fn check_simd<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, id: ast::NodeId) {
let t = tcx.tables().node_id_to_type(id);
pub fn check_simd<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: DefId) {
let t = tcx.item_type(def_id);
match t.sty {
ty::TyAdt(def, substs) if def.is_struct() => {
let fields = &def.struct_variant().fields;
@ -1329,7 +1329,7 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
disr_vals.push(current_disr_val);
}
check_representable(ccx.tcx, sp, id);
check_representable(ccx.tcx, sp, def_id);
}
impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
@ -1342,13 +1342,12 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
fn get_generics(&self, _: Span, id: DefId)
-> Result<&'tcx ty::Generics<'tcx>, ErrorReported>
{
Ok(self.tcx().lookup_generics(id))
Ok(self.tcx().item_generics(id))
}
fn get_item_type_scheme(&self, _: Span, id: DefId)
-> Result<ty::TypeScheme<'tcx>, ErrorReported>
fn get_item_type(&self, _: Span, id: DefId) -> Result<Ty<'tcx>, ErrorReported>
{
Ok(self.tcx().lookup_item_type(id))
Ok(self.tcx().item_type(id))
}
fn get_trait_def(&self, _: Span, id: DefId)
@ -1663,7 +1662,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
/// generic type scheme.
fn instantiate_bounds(&self, span: Span, def_id: DefId, substs: &Substs<'tcx>)
-> ty::InstantiatedPredicates<'tcx> {
let bounds = self.tcx.lookup_predicates(def_id);
let bounds = self.tcx.item_predicates(def_id);
let result = bounds.instantiate(self.tcx, substs);
let result = self.normalize_associated_types_in(span, &result.predicates);
debug!("instantiate_bounds(bounds={:?}, substs={:?}) = {:?}",
@ -1688,7 +1687,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let ty_var = self.next_ty_var();
self.anon_types.borrow_mut().insert(def_id, ty_var);
let item_predicates = self.tcx.lookup_predicates(def_id);
let item_predicates = self.tcx.item_predicates(def_id);
let bounds = item_predicates.instantiate(self.tcx, substs);
let span = self.tcx.map.def_id_span(def_id, codemap::DUMMY_SP);
@ -2743,11 +2742,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
span: Span, // (potential) receiver for this impl
did: DefId)
-> TypeAndSubsts<'tcx> {
let ity = self.tcx.lookup_item_type(did);
let ity = self.tcx.item_type(did);
debug!("impl_self_ty: ity={:?}", ity);
let substs = self.fresh_substs_for_item(span, did);
let substd_ty = self.instantiate_type_scheme(span, &substs, &ity.ty);
let substd_ty = self.instantiate_type_scheme(span, &substs, &ity);
TypeAndSubsts { substs: substs, ty: substd_ty }
}
@ -4185,11 +4184,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Def::VariantCtor(def_id, ..) => {
// Everything but the final segment should have no
// parameters at all.
let mut generics = self.tcx.lookup_generics(def_id);
let mut generics = self.tcx.item_generics(def_id);
if let Some(def_id) = generics.parent {
// Variant and struct constructors use the
// generics of their parent type definition.
generics = self.tcx.lookup_generics(def_id);
generics = self.tcx.item_generics(def_id);
}
type_segment = Some((segments.last().unwrap(), generics));
}
@ -4199,7 +4198,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Def::Const(def_id) |
Def::Static(def_id, _) => {
fn_segment = Some((segments.last().unwrap(),
self.tcx.lookup_generics(def_id)));
self.tcx.item_generics(def_id)));
}
// Case 3. Reference to a method or associated const.
@ -4213,9 +4212,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ty::ImplContainer(_) => {}
}
let generics = self.tcx.lookup_generics(def_id);
let generics = self.tcx.item_generics(def_id);
if segments.len() >= 2 {
let parent_generics = self.tcx.lookup_generics(generics.parent.unwrap());
let parent_generics = self.tcx.item_generics(generics.parent.unwrap());
type_segment = Some((&segments[segments.len() - 2], parent_generics));
} else {
// `<T>::assoc` will end up here, and so can `T::assoc`.
@ -4345,9 +4344,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// The things we are substituting into the type should not contain
// escaping late-bound regions, and nor should the base type scheme.
let scheme = self.tcx.lookup_item_type(def.def_id());
let ty = self.tcx.item_type(def.def_id());
assert!(!substs.has_escaping_regions());
assert!(!scheme.ty.has_escaping_regions());
assert!(!ty.has_escaping_regions());
// Add all the obligations that are required, substituting and
// normalized appropriately.
@ -4358,16 +4357,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// Substitute the values for the type parameters into the type of
// the referenced item.
let ty_substituted = self.instantiate_type_scheme(span, &substs, &scheme.ty);
let ty_substituted = self.instantiate_type_scheme(span, &substs, &ty);
if let Some((ty::ImplContainer(impl_def_id), self_ty)) = ufcs_associated {
// In the case of `Foo<T>::method` and `<Foo<T>>::method`, if `method`
// is inherent, there is no `Self` parameter, instead, the impl needs
// type parameters, which we can infer by unifying the provided `Self`
// with the substituted impl type.
let impl_scheme = self.tcx.lookup_item_type(impl_def_id);
let ty = self.tcx.item_type(impl_def_id);
let impl_ty = self.instantiate_type_scheme(span, &substs, &impl_scheme.ty);
let impl_ty = self.instantiate_type_scheme(span, &substs, &ty);
match self.sub_types(false, TypeOrigin::Misc(span), self_ty, impl_ty) {
Ok(InferOk { obligations, .. }) => {
// FIXME(#32730) propagate obligations

View File

@ -1729,7 +1729,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
// ```
//
// we can thus deduce that `<T as SomeTrait<'a>>::SomeType : 'a`.
let trait_predicates = self.tcx.lookup_predicates(projection_ty.trait_ref.def_id);
let trait_predicates = self.tcx.item_predicates(projection_ty.trait_ref.def_id);
assert_eq!(trait_predicates.parent, None);
let predicates = trait_predicates.predicates.as_slice().to_vec();
traits::elaborate_predicates(self.tcx, predicates)

View File

@ -179,18 +179,18 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
let (mut implied_bounds, self_ty) = match item.container {
ty::TraitContainer(_) => (vec![], fcx.tcx.mk_self_type()),
ty::ImplContainer(def_id) => (fcx.impl_implied_bounds(def_id, span),
fcx.tcx.lookup_item_type(def_id).ty)
fcx.tcx.item_type(def_id))
};
match item.kind {
ty::AssociatedKind::Const => {
let ty = fcx.tcx.lookup_item_type(item.def_id).ty;
let ty = fcx.tcx.item_type(item.def_id);
let ty = fcx.instantiate_type_scheme(span, free_substs, &ty);
fcx.register_wf_obligation(ty, span, code.clone());
}
ty::AssociatedKind::Method => {
reject_shadowing_type_parameters(fcx.tcx, span, item.def_id);
let method_ty = fcx.tcx.lookup_item_type(item.def_id).ty;
let method_ty = fcx.tcx.item_type(item.def_id);
let method_ty = fcx.instantiate_type_scheme(span, free_substs, &method_ty);
let predicates = fcx.instantiate_bounds(span, item.def_id, free_substs);
let fty = match method_ty.sty {
@ -205,7 +205,7 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
}
ty::AssociatedKind::Type => {
if item.has_value {
let ty = fcx.tcx.lookup_item_type(item.def_id).ty;
let ty = fcx.tcx.item_type(item.def_id);
let ty = fcx.instantiate_type_scheme(span, free_substs, &ty);
fcx.register_wf_obligation(ty, span, code.clone());
}
@ -276,7 +276,7 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
//
// 3) that the trait definition does not have any type parameters
let predicates = self.tcx().lookup_predicates(trait_def_id);
let predicates = self.tcx().item_predicates(trait_def_id);
// We must exclude the Self : Trait predicate contained by all
// traits.
@ -353,8 +353,8 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
self.for_item(item).with_fcx(|fcx, this| {
let free_substs = &fcx.parameter_environment.free_substs;
let def_id = fcx.tcx.map.local_def_id(item.id);
let type_scheme = fcx.tcx.lookup_item_type(def_id);
let item_ty = fcx.instantiate_type_scheme(item.span, free_substs, &type_scheme.ty);
let ty = fcx.tcx.item_type(def_id);
let item_ty = fcx.instantiate_type_scheme(item.span, free_substs, &ty);
let bare_fn_ty = match item_ty.sty {
ty::TyFnDef(.., ref bare_fn_ty) => bare_fn_ty,
_ => {
@ -378,11 +378,11 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
debug!("check_item_type: {:?}", item);
self.for_item(item).with_fcx(|fcx, this| {
let type_scheme = fcx.tcx.lookup_item_type(fcx.tcx.map.local_def_id(item.id));
let ty = fcx.tcx.item_type(fcx.tcx.map.local_def_id(item.id));
let item_ty = fcx.instantiate_type_scheme(item.span,
&fcx.parameter_environment
.free_substs,
&type_scheme.ty);
&ty);
fcx.register_wf_obligation(item_ty, item.span, this.code.clone());
@ -417,7 +417,7 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
}
}
None => {
let self_ty = fcx.tcx.tables().node_id_to_type(item.id);
let self_ty = fcx.tcx.item_type(item_def_id);
let self_ty = fcx.instantiate_type_scheme(item.span, free_substs, &self_ty);
fcx.register_wf_obligation(self_ty, ast_self_ty.span, this.code.clone());
}
@ -426,7 +426,7 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
let predicates = fcx.instantiate_bounds(item.span, item_def_id, free_substs);
this.check_where_clauses(fcx, item.span, &predicates);
fcx.impl_implied_bounds(fcx.tcx.map.local_def_id(item.id), item.span)
fcx.impl_implied_bounds(item_def_id, item.span)
});
}
@ -492,7 +492,7 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
let span = method_sig.decl.inputs[0].pat.span;
let free_substs = &fcx.parameter_environment.free_substs;
let method_ty = fcx.tcx.lookup_item_type(method.def_id).ty;
let method_ty = fcx.tcx.item_type(method.def_id);
let fty = fcx.instantiate_type_scheme(span, free_substs, &method_ty);
let sig = fcx.tcx.liberate_late_bound_regions(free_id_outlive, &fty.fn_sig());
@ -523,13 +523,13 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
item: &hir::Item,
ast_generics: &hir::Generics)
{
let ty = self.tcx().tables().node_id_to_type(item.id);
let item_def_id = self.tcx().map.local_def_id(item.id);
let ty = self.tcx().item_type(item_def_id);
if self.tcx().has_error_field(ty) {
return;
}
let item_def_id = self.tcx().map.local_def_id(item.id);
let ty_predicates = self.tcx().lookup_predicates(item_def_id);
let ty_predicates = self.tcx().item_predicates(item_def_id);
assert_eq!(ty_predicates.parent, None);
let variances = self.tcx().item_variances(item_def_id);
@ -583,8 +583,8 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
}
fn reject_shadowing_type_parameters(tcx: TyCtxt, span: Span, def_id: DefId) {
let generics = tcx.lookup_generics(def_id);
let parent = tcx.lookup_generics(generics.parent.unwrap());
let generics = tcx.item_generics(def_id);
let parent = tcx.item_generics(generics.parent.unwrap());
let impl_params: FxHashMap<_, _> = parent.types
.iter()
.map(|tp| (tp.name, tp.def_id))
@ -654,7 +654,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let fields =
struct_def.fields().iter()
.map(|field| {
let field_ty = self.tcx.tables().node_id_to_type(field.id);
let field_ty = self.tcx.item_type(self.tcx.map.local_def_id(field.id));
let field_ty = self.instantiate_type_scheme(field.span,
&self.parameter_environment
.free_substs,
@ -683,7 +683,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
None => {
// Inherent impl: take implied bounds from the self type.
let self_ty = self.tcx.lookup_item_type(impl_def_id).ty;
let self_ty = self.tcx.item_type(impl_def_id);
let self_ty = self.instantiate_type_scheme(span, free_substs, &self_ty);
vec![self_ty]
}

View File

@ -20,8 +20,6 @@ use rustc::ty::adjustment;
use rustc::ty::fold::{TypeFolder,TypeFoldable};
use rustc::infer::{InferCtxt, FixupError};
use rustc::util::nodemap::DefIdMap;
use write_substs_to_tcx;
use write_ty_to_tcx;
use std::cell::Cell;
@ -67,7 +65,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
wbcx.visit_closures();
wbcx.visit_liberated_fn_sigs();
wbcx.visit_fru_field_types();
wbcx.visit_anon_types(item_id);
wbcx.visit_anon_types();
wbcx.visit_deferred_obligations(item_id);
}
}
@ -133,6 +131,12 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
self.fcx.tcx
}
fn write_ty_to_tcx(&self, node_id: ast::NodeId, ty: Ty<'gcx>) {
debug!("write_ty_to_tcx({}, {:?})", node_id, ty);
assert!(!ty.needs_infer());
self.tcx().tables.borrow_mut().node_types.insert(node_id, ty);
}
// Hacky hack: During type-checking, we treat *all* operators
// as potentially overloaded. But then, during writeback, if
// we observe that something like `a+b` is (known to be)
@ -241,7 +245,7 @@ impl<'cx, 'gcx, 'tcx, 'v> Visitor<'v> for WritebackCx<'cx, 'gcx, 'tcx> {
let var_ty = self.fcx.local_ty(l.span, l.id);
let var_ty = self.resolve(&var_ty, ResolvingLocal(l.span));
write_ty_to_tcx(self.fcx.ccx, l.id, var_ty);
self.write_ty_to_tcx(l.id, var_ty);
intravisit::walk_local(self, l);
}
@ -249,7 +253,7 @@ impl<'cx, 'gcx, 'tcx, 'v> Visitor<'v> for WritebackCx<'cx, 'gcx, 'tcx> {
match t.node {
hir::TyArray(ref ty, ref count_expr) => {
self.visit_ty(&ty);
write_ty_to_tcx(self.fcx.ccx, count_expr.id, self.tcx().types.usize);
self.write_ty_to_tcx(count_expr.id, self.tcx().types.usize);
}
hir::TyBareFn(ref function_declaration) => {
intravisit::walk_fn_decl_nopat(self, &function_declaration.decl);
@ -302,13 +306,11 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
}
}
fn visit_anon_types(&self, item_id: ast::NodeId) {
fn visit_anon_types(&self) {
if self.fcx.writeback_errors.get() {
return
}
let item_def_id = self.fcx.tcx.map.local_def_id(item_id);
let gcx = self.tcx().global_tcx();
for (&def_id, &concrete_ty) in self.fcx.anon_types.borrow().iter() {
let reason = ResolvingAnonTy(def_id);
@ -349,10 +351,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
}
});
gcx.register_item_type(def_id, ty::TypeScheme {
ty: outside_ty,
generics: gcx.lookup_generics(item_def_id)
});
gcx.item_types.borrow_mut().insert(def_id, outside_ty);
}
}
@ -363,13 +362,17 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
// Resolve the type of the node with id `id`
let n_ty = self.fcx.node_ty(id);
let n_ty = self.resolve(&n_ty, reason);
write_ty_to_tcx(self.fcx.ccx, id, n_ty);
self.write_ty_to_tcx(id, n_ty);
debug!("Node {} has type {:?}", id, n_ty);
// Resolve any substitutions
self.fcx.opt_node_ty_substs(id, |item_substs| {
write_substs_to_tcx(self.fcx.ccx, id,
self.resolve(item_substs, reason));
let item_substs = self.resolve(item_substs, reason);
if !item_substs.is_noop() {
debug!("write_substs_to_tcx({}, {:?})", id, item_substs);
assert!(!item_substs.substs.needs_infer());
self.tcx().tables.borrow_mut().item_substs.insert(id, item_substs);
}
});
}

View File

@ -106,7 +106,7 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
fn check_implementation(&self, item: &Item) {
let tcx = self.crate_context.tcx;
let impl_did = tcx.map.local_def_id(item.id);
let self_type = tcx.lookup_item_type(impl_did);
let self_type = tcx.item_type(impl_did);
// If there are no traits, then this implementation must have a
// base type.
@ -129,14 +129,14 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
} else {
// Skip inherent impls where the self type is an error
// type. This occurs with e.g. resolve failures (#30589).
if self_type.ty.references_error() {
if self_type.references_error() {
return;
}
// Add the implementation to the mapping from implementation to base
// type def ID, if there is a base type for this implementation and
// the implementation does not have any associated traits.
if let Some(base_def_id) = self.get_base_type_def_id(item.span, self_type.ty) {
if let Some(base_def_id) = self.get_base_type_def_id(item.span, self_type) {
self.add_inherent_impl(base_def_id, impl_did);
}
}
@ -175,8 +175,8 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
}
let method_def_id = items[0];
let self_type = tcx.lookup_item_type(impl_did);
match self_type.ty.sty {
let self_type = tcx.item_type(impl_did);
match self_type.sty {
ty::TyAdt(type_def, _) => {
type_def.set_destructor(method_def_id);
}
@ -232,13 +232,13 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
return;
};
let self_type = tcx.lookup_item_type(impl_did);
let self_type = tcx.item_type(impl_did);
debug!("check_implementations_of_copy: self_type={:?} (bound)",
self_type);
let span = tcx.map.span(impl_node_id);
let param_env = ParameterEnvironment::for_item(tcx, impl_node_id);
let self_type = self_type.ty.subst(tcx, &param_env.free_substs);
let self_type = self_type.subst(tcx, &param_env.free_substs);
assert!(!self_type.has_escaping_regions());
debug!("check_implementations_of_copy: self_type={:?} (free)",
@ -326,7 +326,7 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
return;
};
let source = tcx.lookup_item_type(impl_did).ty;
let source = tcx.item_type(impl_did);
let trait_ref = self.crate_context.tcx.impl_trait_ref(impl_did).unwrap();
let target = trait_ref.substs.type_at(1);
debug!("check_implementations_of_coerce_unsized: {:?} -> {:?} (bound)",

View File

@ -81,7 +81,7 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
// defined in this crate.
debug!("coherence2::orphan check: inherent impl {}",
self.tcx.map.node_to_string(item.id));
let self_ty = self.tcx.lookup_item_type(def_id).ty;
let self_ty = self.tcx.item_type(def_id);
match self_ty.sty {
ty::TyAdt(def, _) => {
self.check_def_id(item, def.did);

View File

@ -13,7 +13,7 @@
# Collect phase
The collect phase of type check has the job of visiting all items,
determining their type, and writing that type into the `tcx.tcache`
determining their type, and writing that type into the `tcx.types`
table. Despite its name, this table does not really operate as a
*cache*, at least not for the types of items defined within the
current crate: we assume that after the collect phase, the types of
@ -22,8 +22,7 @@ all local items will be present in the table.
Unlike most of the types that are present in Rust, the types computed
for each item are in fact type schemes. This means that they are
generic types that may have type parameters. TypeSchemes are
represented by an instance of `ty::TypeScheme`. This combines the
core type along with a list of the bounds for each parameter. Type
represented by a pair of `Generics` and `Ty`. Type
parameters themselves are represented as `ty_param()` instances.
The phasing of type conversion is somewhat complicated. There is no
@ -51,8 +50,8 @@ There are some shortcomings in this design:
- Before walking the set of supertraits for a given trait, you must
call `ensure_super_predicates` on that trait def-id. Otherwise,
`lookup_super_predicates` will result in ICEs.
- Because the type scheme includes defaults, cycles through type
`item_super_predicates` will result in ICEs.
- Because the item generics include defaults, cycles through type
parameter defaults are illegal even if those defaults are never
employed. This is not necessarily a bug.
@ -67,13 +66,13 @@ use rustc_const_eval::EvalHint::UncheckedExprHint;
use rustc_const_eval::{eval_const_expr_partial, report_const_eval_err};
use rustc::ty::subst::Substs;
use rustc::ty::{ToPredicate, ImplContainer, AssociatedItemContainer, TraitContainer};
use rustc::ty::{self, AdtKind, ToPolyTraitRef, Ty, TyCtxt, TypeScheme};
use rustc::ty::{self, AdtKind, ToPolyTraitRef, Ty, TyCtxt};
use rustc::ty::util::IntTypeExt;
use rscope::*;
use rustc::dep_graph::DepNode;
use util::common::{ErrorReported, MemoizationMap};
use util::nodemap::{NodeMap, FxHashMap, FxHashSet};
use {CrateCtxt, write_ty_to_tcx};
use CrateCtxt;
use rustc_const_math::ConstInt;
@ -132,6 +131,15 @@ struct CollectItemTypesVisitor<'a, 'tcx: 'a> {
impl<'a, 'tcx, 'v> intravisit::Visitor<'v> for CollectItemTypesVisitor<'a, 'tcx> {
fn visit_item(&mut self, item: &hir::Item) {
convert_item(self.ccx, item);
intravisit::walk_item(self, item);
}
fn visit_ty(&mut self, ty: &hir::Ty) {
if let hir::TyImplTrait(..) = ty.node {
let def_id = self.ccx.tcx.map.local_def_id(ty.id);
generics_of_def_id(self.ccx, def_id);
}
intravisit::walk_ty(self, ty);
}
}
@ -308,11 +316,9 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
})
}
fn get_item_type_scheme(&self, span: Span, id: DefId)
-> Result<ty::TypeScheme<'tcx>, ErrorReported>
{
fn get_item_type(&self, span: Span, id: DefId) -> Result<Ty<'tcx>, ErrorReported> {
self.ccx.cycle_check(span, AstConvRequest::GetItemTypeScheme(id), || {
Ok(type_scheme_of_def_id(self.ccx, id))
Ok(type_of_def_id(self.ccx, id))
})
}
@ -447,7 +453,7 @@ impl<'tcx> GetTypeParameterBounds<'tcx> for ty::GenericPredicates<'tcx> {
let def = astconv.tcx().type_parameter_def(node_id);
let mut results = self.parent.map_or(vec![], |def_id| {
let parent = astconv.tcx().lookup_predicates(def_id);
let parent = astconv.tcx().item_predicates(def_id);
parent.get_type_parameter_bounds(astconv, span, node_id)
});
@ -546,16 +552,11 @@ fn convert_field<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
{
let tt = ccx.icx(struct_predicates).to_ty(&ExplicitRscope, &field.ty);
ty_f.fulfill_ty(tt);
write_ty_to_tcx(ccx, field.id, tt);
/* add the field to the tcache */
ccx.tcx.register_item_type(ccx.tcx.map.local_def_id(field.id),
ty::TypeScheme {
generics: struct_generics,
ty: tt
});
ccx.tcx.predicates.borrow_mut().insert(ccx.tcx.map.local_def_id(field.id),
struct_predicates.clone());
let def_id = ccx.tcx.map.local_def_id(field.id);
ccx.tcx.item_types.borrow_mut().insert(def_id, tt);
ccx.tcx.generics.borrow_mut().insert(def_id, struct_generics);
ccx.tcx.predicates.borrow_mut().insert(def_id, struct_predicates.clone());
}
fn convert_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
@ -580,8 +581,7 @@ fn convert_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
let substs = mk_item_substs(&ccx.icx(&(rcvr_ty_predicates, &sig.generics)),
ccx.tcx.map.span(id), def_id);
let fty = ccx.tcx.mk_fn_def(def_id, substs, fty);
ccx.tcx.tcache.borrow_mut().insert(def_id, fty);
write_ty_to_tcx(ccx, id, fty);
ccx.tcx.item_types.borrow_mut().insert(def_id, fty);
ccx.tcx.predicates.borrow_mut().insert(def_id, ty_generic_predicates);
}
@ -596,9 +596,7 @@ fn convert_associated_const<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
};
let def_id = ccx.tcx.map.local_def_id(id);
ccx.tcx.predicates.borrow_mut().insert(def_id, predicates);
ccx.tcx.tcache.borrow_mut().insert(def_id, ty);
write_ty_to_tcx(ccx, id, ty);
ccx.tcx.item_types.borrow_mut().insert(def_id, ty);
}
fn convert_associated_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
@ -614,8 +612,7 @@ fn convert_associated_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
ccx.tcx.predicates.borrow_mut().insert(def_id, predicates);
if let Some(ty) = ty {
ccx.tcx.tcache.borrow_mut().insert(def_id, ty);
write_ty_to_tcx(ccx, id, ty);
ccx.tcx.item_types.borrow_mut().insert(def_id, ty);
}
}
@ -662,11 +659,13 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
}
hir::ItemEnum(ref enum_definition, _) => {
let def_id = ccx.tcx.map.local_def_id(it.id);
let scheme = type_scheme_of_def_id(ccx, def_id);
let ty = type_of_def_id(ccx, def_id);
let generics = generics_of_def_id(ccx, def_id);
let predicates = predicates_of_item(ccx, it);
convert_enum_variant_types(ccx,
tcx.lookup_adt_def_master(ccx.tcx.map.local_def_id(it.id)),
scheme,
ty,
generics,
predicates,
&enum_definition.variants);
},
@ -690,18 +689,15 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
// Create generics from the generics specified in the impl head.
debug!("convert: ast_generics={:?}", generics);
let def_id = ccx.tcx.map.local_def_id(it.id);
let ty_generics = generics_of_def_id(ccx, def_id);
generics_of_def_id(ccx, def_id);
let mut ty_predicates =
ty_generic_predicates(ccx, generics, None, vec![], false);
debug!("convert: impl_bounds={:?}", ty_predicates);
let selfty = ccx.icx(&ty_predicates).to_ty(&ExplicitRscope, &selfty);
write_ty_to_tcx(ccx, it.id, selfty);
tcx.item_types.borrow_mut().insert(def_id, selfty);
tcx.register_item_type(def_id,
TypeScheme { generics: ty_generics,
ty: selfty });
let trait_ref = opt_trait_ref.as_ref().map(|ast_trait_ref| {
AstConv::instantiate_mono_trait_ref(&ccx.icx(&ty_predicates),
&ExplicitRscope,
@ -742,14 +738,10 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
if let hir::ImplItemKind::Const(ref ty, _) = impl_item.node {
let const_def_id = ccx.tcx.map.local_def_id(impl_item.id);
let ty_generics = generics_of_def_id(ccx, const_def_id);
generics_of_def_id(ccx, const_def_id);
let ty = ccx.icx(&ty_predicates)
.to_ty(&ExplicitRscope, &ty);
tcx.register_item_type(const_def_id,
TypeScheme {
generics: ty_generics,
ty: ty,
});
tcx.item_types.borrow_mut().insert(const_def_id, ty);
convert_associated_const(ccx, ImplContainer(def_id),
impl_item.id, ty);
}
@ -788,7 +780,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
let _: Result<(), ErrorReported> = // any error is already reported, can ignore
ccx.ensure_super_predicates(it.span, def_id);
convert_trait_predicates(ccx, it);
let trait_predicates = tcx.lookup_predicates(def_id);
let trait_predicates = tcx.item_predicates(def_id);
debug!("convert: trait_bounds={:?}", trait_predicates);
@ -799,14 +791,10 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
for trait_item in trait_items {
if let hir::ConstTraitItem(ref ty, _) = trait_item.node {
let const_def_id = ccx.tcx.map.local_def_id(trait_item.id);
let ty_generics = generics_of_def_id(ccx, const_def_id);
generics_of_def_id(ccx, const_def_id);
let ty = ccx.icx(&trait_predicates)
.to_ty(&ExplicitRscope, ty);
tcx.register_item_type(const_def_id,
TypeScheme {
generics: ty_generics,
ty: ty,
});
tcx.item_types.borrow_mut().insert(const_def_id, ty);
convert_associated_const(ccx, container, trait_item.id, ty)
}
}
@ -840,28 +828,31 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
hir::ItemStruct(ref struct_def, _) |
hir::ItemUnion(ref struct_def, _) => {
let def_id = ccx.tcx.map.local_def_id(it.id);
let scheme = type_scheme_of_def_id(ccx, def_id);
let ty = type_of_def_id(ccx, def_id);
let generics = generics_of_def_id(ccx, def_id);
let predicates = predicates_of_item(ccx, it);
let variant = tcx.lookup_adt_def_master(def_id).struct_variant();
for (f, ty_f) in struct_def.fields().iter().zip(variant.fields.iter()) {
convert_field(ccx, &scheme.generics, &predicates, f, ty_f)
convert_field(ccx, generics, &predicates, f, ty_f)
}
if !struct_def.is_struct() {
convert_variant_ctor(ccx, struct_def.id(), variant, scheme, predicates);
convert_variant_ctor(ccx, struct_def.id(), variant, ty, predicates);
}
},
hir::ItemTy(_, ref generics) => {
ensure_no_ty_param_bounds(ccx, it.span, generics, "type");
let def_id = ccx.tcx.map.local_def_id(it.id);
type_scheme_of_def_id(ccx, def_id);
type_of_def_id(ccx, def_id);
generics_of_def_id(ccx, def_id);
predicates_of_item(ccx, it);
},
_ => {
let def_id = ccx.tcx.map.local_def_id(it.id);
type_scheme_of_def_id(ccx, def_id);
type_of_def_id(ccx, def_id);
generics_of_def_id(ccx, def_id);
predicates_of_item(ccx, it);
},
}
@ -870,13 +861,13 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
fn convert_variant_ctor<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
ctor_id: ast::NodeId,
variant: ty::VariantDef<'tcx>,
scheme: ty::TypeScheme<'tcx>,
ty: Ty<'tcx>,
predicates: ty::GenericPredicates<'tcx>) {
let tcx = ccx.tcx;
let def_id = tcx.map.local_def_id(ctor_id);
generics_of_def_id(ccx, def_id);
let ctor_ty = match variant.ctor_kind {
CtorKind::Fictive | CtorKind::Const => scheme.ty,
CtorKind::Fictive | CtorKind::Const => ty,
CtorKind::Fn => {
let inputs: Vec<_> =
variant.fields
@ -890,26 +881,26 @@ fn convert_variant_ctor<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
abi: abi::Abi::Rust,
sig: ty::Binder(ty::FnSig {
inputs: inputs,
output: scheme.ty,
output: ty,
variadic: false
})
}))
}
};
write_ty_to_tcx(ccx, ctor_id, ctor_ty);
tcx.tcache.borrow_mut().insert(def_id, ctor_ty);
tcx.item_types.borrow_mut().insert(def_id, ctor_ty);
tcx.predicates.borrow_mut().insert(tcx.map.local_def_id(ctor_id), predicates);
}
fn convert_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
def: ty::AdtDefMaster<'tcx>,
scheme: ty::TypeScheme<'tcx>,
ty: Ty<'tcx>,
generics: &'tcx ty::Generics<'tcx>,
predicates: ty::GenericPredicates<'tcx>,
variants: &[hir::Variant]) {
// fill the field types
for (variant, ty_variant) in variants.iter().zip(def.variants.iter()) {
for (f, ty_f) in variant.node.data.fields().iter().zip(ty_variant.fields.iter()) {
convert_field(ccx, &scheme.generics, &predicates, f, ty_f)
convert_field(ccx, generics, &predicates, f, ty_f)
}
// Convert the ctor, if any. This also registers the variant as
@ -918,7 +909,7 @@ fn convert_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
ccx,
variant.node.data.id(),
ty_variant,
scheme.clone(),
ty,
predicates.clone()
);
}
@ -1216,7 +1207,7 @@ fn convert_trait_predicates<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &hir::Item)
}
};
let super_predicates = ccx.tcx.lookup_super_predicates(def_id);
let super_predicates = ccx.tcx.item_super_predicates(def_id);
// `ty_generic_predicates` below will consider the bounds on the type
// parameters (including `Self`) and the explicit where-clauses,
@ -1283,7 +1274,7 @@ fn generics_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
let node_id = if let Some(id) = tcx.map.as_local_node_id(def_id) {
id
} else {
return tcx.lookup_generics(def_id);
return tcx.item_generics(def_id);
};
tcx.generics.memoize(def_id, || {
use rustc::hir::map::*;
@ -1298,6 +1289,18 @@ fn generics_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
let parent_id = tcx.map.get_parent(node_id);
Some(tcx.map.local_def_id(parent_id))
}
NodeTy(&hir::Ty { node: hir::TyImplTrait(..), .. }) => {
let mut parent_id = node_id;
loop {
match tcx.map.get(parent_id) {
NodeItem(_) | NodeImplItem(_) | NodeTraitItem(_) => break,
_ => {
parent_id = tcx.map.get_parent_node(parent_id);
}
}
}
Some(tcx.map.local_def_id(parent_id))
}
_ => None
};
@ -1377,13 +1380,11 @@ fn generics_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
let mut own_start = has_self as u32;
let (parent_regions, parent_types) = parent_def_id.map_or((0, 0), |def_id| {
let generics = generics_of_def_id(ccx, def_id);
assert_eq!(generics.parent, None);
assert_eq!(generics.parent_regions, 0);
assert_eq!(generics.parent_types, 0);
assert_eq!(has_self, false);
parent_has_self = generics.has_self;
own_start = generics.count() as u32;
(generics.regions.len() as u32, generics.types.len() as u32)
(generics.parent_regions + generics.regions.len() as u32,
generics.parent_types + generics.types.len() as u32)
});
let early_lifetimes = early_bound_lifetimes_from_generics(ccx, ast_generics);
@ -1436,12 +1437,15 @@ fn type_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
let node_id = if let Some(id) = ccx.tcx.map.as_local_node_id(def_id) {
id
} else {
return ccx.tcx.lookup_item_type(def_id).ty;
return ccx.tcx.item_type(def_id);
};
ccx.tcx.tcache.memoize(def_id, || {
ccx.tcx.item_types.memoize(def_id, || {
use rustc::hir::map::*;
use rustc::hir::*;
// Alway bring in generics, as computing the type needs them.
generics_of_def_id(ccx, def_id);
let ty = match ccx.tcx.map.get(node_id) {
NodeItem(item) => {
match item.node {
@ -1505,24 +1509,10 @@ fn type_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
}
};
write_ty_to_tcx(ccx, node_id, ty);
ty
})
}
fn type_scheme_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a,'tcx>,
def_id: DefId)
-> ty::TypeScheme<'tcx> {
if def_id.is_local() {
ty::TypeScheme {
generics: generics_of_def_id(ccx, def_id),
ty: type_of_def_id(ccx, def_id)
}
} else {
ccx.tcx.lookup_item_type(def_id)
}
}
fn predicates_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
it: &hir::Item)
-> ty::GenericPredicates<'tcx> {
@ -1554,7 +1544,8 @@ fn convert_foreign_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
// moral failing, but at the moment it seems like the only
// convenient way to extract the ABI. - ndm
let def_id = ccx.tcx.map.local_def_id(it.id);
type_scheme_of_def_id(ccx, def_id);
type_of_def_id(ccx, def_id);
generics_of_def_id(ccx, def_id);
let no_generics = hir::Generics::empty();
let generics = match it.node {
@ -1648,7 +1639,7 @@ fn ty_generic_predicates<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
let ref base_predicates = match parent {
Some(def_id) => {
assert_eq!(super_predicates, vec![]);
tcx.lookup_predicates(def_id)
tcx.item_predicates(def_id)
}
None => {
ty::GenericPredicates {
@ -2035,14 +2026,14 @@ fn enforce_impl_params_are_constrained<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
impl_predicates: &mut ty::GenericPredicates<'tcx>,
impl_def_id: DefId)
{
let impl_scheme = ccx.tcx.lookup_item_type(impl_def_id);
let impl_ty = ccx.tcx.item_type(impl_def_id);
let impl_trait_ref = ccx.tcx.impl_trait_ref(impl_def_id);
// The trait reference is an input, so find all type parameters
// reachable from there, to start (if this is an inherent impl,
// then just examine the self type).
let mut input_parameters: FxHashSet<_> =
ctp::parameters_for(&impl_scheme.ty, false).into_iter().collect();
ctp::parameters_for(&impl_ty, false).into_iter().collect();
if let Some(ref trait_ref) = impl_trait_ref {
input_parameters.extend(ctp::parameters_for(trait_ref, false));
}
@ -2066,12 +2057,12 @@ fn enforce_impl_lifetimes_are_constrained<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
impl_items: &[hir::ImplItem])
{
// Every lifetime used in an associated type must be constrained.
let impl_scheme = ccx.tcx.lookup_item_type(impl_def_id);
let impl_predicates = ccx.tcx.lookup_predicates(impl_def_id);
let impl_ty = ccx.tcx.item_type(impl_def_id);
let impl_predicates = ccx.tcx.item_predicates(impl_def_id);
let impl_trait_ref = ccx.tcx.impl_trait_ref(impl_def_id);
let mut input_parameters: FxHashSet<_> =
ctp::parameters_for(&impl_scheme.ty, false).into_iter().collect();
ctp::parameters_for(&impl_ty, false).into_iter().collect();
if let Some(ref trait_ref) = impl_trait_ref {
input_parameters.extend(ctp::parameters_for(trait_ref, false));
}
@ -2085,10 +2076,10 @@ fn enforce_impl_lifetimes_are_constrained<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
item.kind == ty::AssociatedKind::Type && item.has_value
})
.flat_map(|def_id| {
ctp::parameters_for(&ccx.tcx.lookup_item_type(def_id).ty, true)
ctp::parameters_for(&ccx.tcx.item_type(def_id), true)
}).collect();
for (ty_lifetime, lifetime) in impl_scheme.generics.regions.iter()
for (ty_lifetime, lifetime) in ccx.tcx.item_generics(impl_def_id).regions.iter()
.zip(&ast_generics.lifetimes)
{
let param = ctp::Parameter::from(ty_lifetime.to_early_bound_region_data());

View File

@ -44,7 +44,7 @@ independently:
into the `ty` representation
- collect: computes the types of each top-level item and enters them into
the `cx.tcache` table for later use
the `tcx.types` table for later use
- coherence: enforces coherence rules, builds some tables
@ -108,7 +108,7 @@ use dep_graph::DepNode;
use hir::map as hir_map;
use rustc::infer::{InferOk, TypeOrigin};
use rustc::ty::subst::Substs;
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc::ty::{self, Ty, TyCtxt};
use rustc::traits::{self, Reveal};
use session::{config, CompileResult};
use util::common::time;
@ -159,27 +159,6 @@ pub struct CrateCtxt<'a, 'tcx: 'a> {
pub deferred_obligations: RefCell<NodeMap<Vec<traits::DeferredObligation<'tcx>>>>,
}
// Functions that write types into the node type table
fn write_ty_to_tcx<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, node_id: ast::NodeId, ty: Ty<'tcx>) {
debug!("write_ty_to_tcx({}, {:?})", node_id, ty);
assert!(!ty.needs_infer());
ccx.tcx.node_type_insert(node_id, ty);
}
fn write_substs_to_tcx<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
node_id: ast::NodeId,
item_substs: ty::ItemSubsts<'tcx>) {
if !item_substs.is_noop() {
debug!("write_substs_to_tcx({}, {:?})",
node_id,
item_substs);
assert!(!item_substs.substs.needs_infer());
ccx.tcx.tables.borrow_mut().item_substs.insert(node_id, item_substs);
}
}
fn require_c_abi_if_variadic(tcx: TyCtxt,
decl: &hir::FnDecl,
abi: Abi,
@ -216,7 +195,8 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
main_id: ast::NodeId,
main_span: Span) {
let tcx = ccx.tcx;
let main_t = tcx.tables().node_id_to_type(main_id);
let main_def_id = tcx.map.local_def_id(main_id);
let main_t = tcx.item_type(main_def_id);
match main_t.sty {
ty::TyFnDef(..) => {
match tcx.map.find(main_id) {
@ -237,7 +217,6 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
}
_ => ()
}
let main_def_id = tcx.map.local_def_id(main_id);
let substs = tcx.intern_substs(&[]);
let se_ty = tcx.mk_fn_def(main_def_id, substs,
tcx.mk_bare_fn(ty::BareFnTy {
@ -268,7 +247,8 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
start_id: ast::NodeId,
start_span: Span) {
let tcx = ccx.tcx;
let start_t = tcx.tables().node_id_to_type(start_id);
let start_def_id = ccx.tcx.map.local_def_id(start_id);
let start_t = tcx.item_type(start_def_id);
match start_t.sty {
ty::TyFnDef(..) => {
match tcx.map.find(start_id) {
@ -289,7 +269,6 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
_ => ()
}
let start_def_id = ccx.tcx.map.local_def_id(start_id);
let substs = tcx.intern_substs(&[]);
let se_ty = tcx.mk_fn_def(start_def_id, substs,
tcx.mk_bare_fn(ty::BareFnTy {

View File

@ -82,16 +82,16 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ConstraintContext<'a, 'tcx> {
hir::ItemEnum(..) |
hir::ItemStruct(..) |
hir::ItemUnion(..) => {
let scheme = tcx.lookup_item_type(did);
let generics = tcx.item_generics(did);
// Not entirely obvious: constraints on structs/enums do not
// affect the variance of their type parameters. See discussion
// in comment at top of module.
//
// self.add_constraints_from_generics(&scheme.generics);
// self.add_constraints_from_generics(generics);
for field in tcx.lookup_adt_def(did).all_fields() {
self.add_constraints_from_ty(&scheme.generics,
self.add_constraints_from_ty(generics,
field.unsubst_ty(),
self.covariant);
}
@ -336,7 +336,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
}
ty::TyAdt(def, substs) => {
let item_type = self.tcx().lookup_item_type(def.did);
let adt_generics = self.tcx().item_generics(def.did);
// This edge is actually implied by the call to
// `lookup_trait_def`, but I'm trying to be future-proof. See
@ -345,8 +345,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
self.add_constraints_from_substs(generics,
def.did,
&item_type.generics.types,
&item_type.generics.regions,
&adt_generics.types,
&adt_generics.regions,
substs,
variance);
}

View File

@ -164,7 +164,7 @@ pub fn build_external_trait<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tc
did: DefId) -> clean::Trait {
let def = tcx.lookup_trait_def(did);
let trait_items = tcx.associated_items(did).map(|item| item.clean(cx)).collect();
let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);
let generics = (def.generics, &predicates).clean(cx);
let generics = filter_non_trait_generics(did, generics);
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
@ -178,8 +178,8 @@ pub fn build_external_trait<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tc
fn build_external_function<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Function {
let t = tcx.lookup_item_type(did);
let (decl, style, abi) = match t.ty.sty {
let ty = tcx.item_type(did);
let (decl, style, abi) = match ty.sty {
ty::TyFnDef(.., ref f) => ((did, &f.sig).clean(cx), f.unsafety, f.abi),
_ => panic!("bad function"),
};
@ -190,10 +190,10 @@ fn build_external_function<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx
hir::Constness::NotConst
};
let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);
clean::Function {
decl: decl,
generics: (t.generics, &predicates).clean(cx),
generics: (tcx.item_generics(did), &predicates).clean(cx),
unsafety: style,
constness: constness,
abi: abi,
@ -202,11 +202,10 @@ fn build_external_function<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx
fn build_enum<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Enum {
let t = tcx.lookup_item_type(did);
let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);
clean::Enum {
generics: (t.generics, &predicates).clean(cx),
generics: (tcx.item_generics(did), &predicates).clean(cx),
variants_stripped: false,
variants: tcx.lookup_adt_def(did).variants.clean(cx),
}
@ -214,8 +213,7 @@ fn build_enum<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
fn build_struct<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Struct {
let t = tcx.lookup_item_type(did);
let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);
let variant = tcx.lookup_adt_def(did).struct_variant();
clean::Struct {
@ -224,7 +222,7 @@ fn build_struct<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
CtorKind::Fn => doctree::Tuple,
CtorKind::Const => doctree::Unit,
},
generics: (t.generics, &predicates).clean(cx),
generics: (tcx.item_generics(did), &predicates).clean(cx),
fields: variant.fields.clean(cx),
fields_stripped: false,
}
@ -232,13 +230,12 @@ fn build_struct<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
fn build_union<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Union {
let t = tcx.lookup_item_type(did);
let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);
let variant = tcx.lookup_adt_def(did).struct_variant();
clean::Union {
struct_type: doctree::Plain,
generics: (t.generics, &predicates).clean(cx),
generics: (tcx.item_generics(did), &predicates).clean(cx),
fields: variant.fields.clean(cx),
fields_stripped: false,
}
@ -246,12 +243,11 @@ fn build_union<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
fn build_type_alias<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Typedef {
let t = tcx.lookup_item_type(did);
let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);
clean::Typedef {
type_: t.ty.clean(cx),
generics: (t.generics, &predicates).clean(cx),
type_: tcx.item_type(did).clean(cx),
generics: (tcx.item_generics(did), &predicates).clean(cx),
}
}
@ -354,8 +350,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
});
}
let ty = tcx.lookup_item_type(did);
let for_ = ty.ty.clean(cx);
let for_ = tcx.item_type(did).clean(cx);
// Only inline impl if the implementing type is
// reachable in rustdoc generated documentation
@ -365,11 +360,10 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
}
}
let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);
let trait_items = tcx.associated_items(did).filter_map(|item| {
match item.kind {
ty::AssociatedKind::Const => {
let type_scheme = tcx.lookup_item_type(item.def_id);
let default = if item.has_value {
Some(pprust::expr_to_string(
lookup_const_by_id(tcx, item.def_id, None).unwrap().0))
@ -379,7 +373,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
Some(clean::Item {
name: Some(item.name.clean(cx)),
inner: clean::AssociatedConstItem(
type_scheme.ty.clean(cx),
tcx.item_type(item.def_id).clean(cx),
default,
),
source: clean::Span::empty(),
@ -419,7 +413,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
}
ty::AssociatedKind::Type => {
let typedef = clean::Typedef {
type_: tcx.lookup_item_type(item.def_id).ty.clean(cx),
type_: tcx.item_type(item.def_id).clean(cx),
generics: clean::Generics {
lifetimes: vec![],
type_params: vec![],
@ -463,7 +457,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
provided_trait_methods: provided,
trait_: trait_,
for_: for_,
generics: (ty.generics, &predicates).clean(cx),
generics: (tcx.item_generics(did), &predicates).clean(cx),
items: trait_items,
polarity: Some(polarity.clean(cx)),
}),
@ -514,7 +508,7 @@ fn build_const<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
debug!("got snippet {}", sn);
clean::Constant {
type_: ty.map(|t| t.clean(cx)).unwrap_or_else(|| tcx.lookup_item_type(did).ty.clean(cx)),
type_: ty.map(|t| t.clean(cx)).unwrap_or_else(|| tcx.item_type(did).clean(cx)),
expr: sn
}
}
@ -523,7 +517,7 @@ fn build_static<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId,
mutable: bool) -> clean::Static {
clean::Static {
type_: tcx.lookup_item_type(did).ty.clean(cx),
type_: tcx.item_type(did).clean(cx),
mutability: if mutable {clean::Mutable} else {clean::Immutable},
expr: "\n\n\n".to_string(), // trigger the "[definition]" links
}

View File

@ -1342,13 +1342,13 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
fn clean(&self, cx: &DocContext) -> Item {
let inner = match self.kind {
ty::AssociatedKind::Const => {
let ty = cx.tcx().lookup_item_type(self.def_id).ty;
let ty = cx.tcx().item_type(self.def_id);
AssociatedConstItem(ty.clean(cx), None)
}
ty::AssociatedKind::Method => {
let generics = (cx.tcx().lookup_generics(self.def_id),
&cx.tcx().lookup_predicates(self.def_id)).clean(cx);
let fty = match cx.tcx().lookup_item_type(self.def_id).ty.sty {
let generics = (cx.tcx().item_generics(self.def_id),
&cx.tcx().item_predicates(self.def_id)).clean(cx);
let fty = match cx.tcx().item_type(self.def_id).sty {
ty::TyFnDef(_, _, f) => f,
_ => unreachable!()
};
@ -1357,7 +1357,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
if self.method_has_self_argument {
let self_ty = match self.container {
ty::ImplContainer(def_id) => {
cx.tcx().lookup_item_type(def_id).ty
cx.tcx().item_type(def_id)
}
ty::TraitContainer(_) => cx.tcx().mk_self_type()
};
@ -1405,7 +1405,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
// all of the generics from there and then look for bounds that are
// applied to this associated type in question.
let def = cx.tcx().lookup_trait_def(did);
let predicates = cx.tcx().lookup_predicates(did);
let predicates = cx.tcx().item_predicates(did);
let generics = (def.generics, &predicates).clean(cx);
generics.where_predicates.iter().filter_map(|pred| {
let (name, self_type, trait_, bounds) = match *pred {
@ -1441,7 +1441,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
}
let ty = if self.has_value {
Some(cx.tcx().lookup_item_type(self.def_id).ty)
Some(cx.tcx().item_type(self.def_id))
} else {
None
};
@ -1901,7 +1901,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
ty::TyAnon(def_id, substs) => {
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
// by looking up the projections associated with the def_id.
let item_predicates = cx.tcx().lookup_predicates(def_id);
let item_predicates = cx.tcx().item_predicates(def_id);
let substs = cx.tcx().lift(&substs).unwrap();
let bounds = item_predicates.instantiate(cx.tcx(), substs);
ImplTrait(bounds.predicates.into_iter().filter_map(|predicate| {

View File

@ -153,7 +153,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext, child: DefId,
if child == trait_ {
return true
}
let predicates = cx.tcx().lookup_super_predicates(child).predicates;
let predicates = cx.tcx().item_super_predicates(child).predicates;
predicates.iter().filter_map(|pred| {
if let ty::Predicate::Trait(ref pred) = *pred {
if pred.0.trait_ref.self_ty().is_self() {