use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
use middle::privacy::AccessLevels;
use middle::resolve_lifetime::ObjectLifetimeDefault;
+use middle::region::CodeExtent;
use mir::Mir;
use traits;
use ty;
pub use self::instance::{Instance, InstanceDef};
-pub use self::trait_def::{TraitDef, TraitFlags};
+pub use self::trait_def::TraitDef;
pub use self::maps::queries;
impl RegionParameterDef {
pub fn to_early_bound_region_data(&self) -> ty::EarlyBoundRegion {
ty::EarlyBoundRegion {
+ def_id: self.def_id,
index: self.index,
name: self.name,
}
}
+ pub fn to_bound_region(&self) -> ty::BoundRegion {
+ self.to_early_bound_region_data().to_bound_region()
+ }
+}
+
+impl ty::EarlyBoundRegion {
pub fn to_bound_region(&self) -> ty::BoundRegion {
ty::BoundRegion::BrNamed(self.def_id, self.name)
}
instantiated.predicates.extend(self.predicates.iter().map(|p| p.subst(tcx, substs)))
}
+ pub fn instantiate_identity(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>)
+ -> InstantiatedPredicates<'tcx> {
+ let mut instantiated = InstantiatedPredicates::empty();
+ self.instantiate_identity_into(tcx, &mut instantiated);
+ instantiated
+ }
+
+ fn instantiate_identity_into(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
+ instantiated: &mut InstantiatedPredicates<'tcx>) {
+ if let Some(def_id) = self.parent {
+ tcx.predicates_of(def_id).instantiate_identity_into(tcx, instantiated);
+ }
+ instantiated.predicates.extend(&self.predicates)
+ }
+
pub fn instantiate_supertrait(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
poly_trait_ref: &ty::PolyTraitRef<'tcx>)
-> InstantiatedPredicates<'tcx>
/// more distinctions clearer.
#[derive(Clone)]
pub struct ParameterEnvironment<'tcx> {
- /// See `construct_free_substs` for details.
- pub free_substs: &'tcx Substs<'tcx>,
-
/// Obligations that the caller must satisfy. This is basically
/// the set of bounds on the in-scope type parameters, translated
/// into Obligations, and elaborated and normalized.
-> ParameterEnvironment<'tcx>
{
ParameterEnvironment {
- free_substs: self.free_substs,
caller_bounds: caller_bounds,
is_copy_cache: RefCell::new(FxHashMap()),
is_sized_cache: RefCell::new(FxHashMap()),
}
pub fn trait_has_default_impl(self, trait_def_id: DefId) -> bool {
- let def = self.trait_def(trait_def_id);
- def.flags.get().intersects(TraitFlags::HAS_DEFAULT_IMPL)
- }
-
- /// Populates the type context with all the implementations for the given
- /// trait if necessary.
- pub fn populate_implementations_for_trait_if_necessary(self, trait_id: DefId) {
- if trait_id.is_local() {
- return
- }
-
- // The type is not local, hence we are reading this out of
- // metadata and don't need to track edges.
- let _ignore = self.dep_graph.in_ignore();
-
- let def = self.trait_def(trait_id);
- if def.flags.get().intersects(TraitFlags::HAS_REMOTE_IMPLS) {
- return;
- }
-
- debug!("populate_implementations_for_trait_if_necessary: searching for {:?}", def);
-
- for impl_def_id in self.sess.cstore.implementations_of_trait(Some(trait_id)) {
- let trait_ref = self.impl_trait_ref(impl_def_id).unwrap();
-
- // Record the trait->implementation mapping.
- let parent = self.impl_parent(impl_def_id).unwrap_or(trait_id);
- def.record_remote_impl(self, impl_def_id, trait_ref, parent);
- }
-
- def.flags.set(def.flags.get() | TraitFlags::HAS_REMOTE_IMPLS);
+ self.trait_def(trait_def_id).has_default_impl
}
/// Given the def_id of an impl, return the def_id of the trait it implements.
/// are no free type/lifetime parameters in scope.
pub fn empty_parameter_environment(self) -> ParameterEnvironment<'tcx> {
ty::ParameterEnvironment {
- free_substs: self.intern_substs(&[]),
caller_bounds: Slice::empty(),
is_copy_cache: RefCell::new(FxHashMap()),
is_sized_cache: RefCell::new(FxHashMap()),
}
}
- /// Constructs and returns a substitution that can be applied to move from
- /// the "outer" view of a type or method to the "inner" view.
- /// In general, this means converting from bound parameters to
- /// free parameters. Since we currently represent bound/free type
- /// parameters in the same way, this only has an effect on regions.
- pub fn construct_free_substs(self, def_id: DefId) -> &'gcx Substs<'gcx> {
-
- let substs = Substs::for_item(self.global_tcx(), def_id, |def, _| {
- // map bound 'a => free 'a
- self.global_tcx().mk_region(ReFree(FreeRegion {
- scope: def_id,
- bound_region: def.to_bound_region()
- }))
- }, |def, _| {
- // map T => T
- self.global_tcx().mk_param_from_def(def)
- });
-
- debug!("parameter_environment: {:?}", substs);
- substs
- }
-
/// See `ParameterEnvironment` struct def'n for details.
pub fn parameter_environment(self, def_id: DefId) -> ParameterEnvironment<'gcx> {
- //
- // Construct the free substs.
- //
-
- let free_substs = self.construct_free_substs(def_id);
-
//
// Compute the bounds on Self and the type parameters.
//
let tcx = self.global_tcx();
- let generic_predicates = tcx.predicates_of(def_id);
- let bounds = generic_predicates.instantiate(tcx, free_substs);
+ let bounds = tcx.predicates_of(def_id).instantiate_identity(tcx);
let predicates = bounds.predicates;
// Finally, we have to normalize the bounds in the environment, in
//
let unnormalized_env = ty::ParameterEnvironment {
- free_substs,
caller_bounds: tcx.intern_predicates(&predicates),
is_copy_cache: RefCell::new(FxHashMap()),
is_sized_cache: RefCell::new(FxHashMap()),
}
pub fn node_scope_region(self, id: NodeId) -> Region<'tcx> {
- self.mk_region(ty::ReScope(self.node_extent(id)))
+ self.mk_region(ty::ReScope(CodeExtent::Misc(id)))
}
/// Looks up the span of `impl_did` if the impl is local; otherwise returns `Err`
adt_dtorck_constraint,
def_span,
trait_of_item,
+ trait_impls_of: trait_def::trait_impls_of_provider,
+ relevant_trait_impls_for: trait_def::relevant_trait_impls_provider,
..*providers
};
}
*providers = ty::maps::Providers {
adt_sized_constraint,
adt_dtorck_constraint,
+ trait_impls_of: trait_def::trait_impls_of_provider,
+ relevant_trait_impls_for: trait_def::relevant_trait_impls_provider,
..*providers
};
}