Deprecation(D),
ItemBodyNestedBodies(D),
ConstIsRvaluePromotableToStatic(D),
+ TraitOfItem(D),
IsMirAvailable(D),
ItemAttrs(D),
FnArgNames(D),
Deprecation(ref d) => op(d).map(Deprecation),
ItemAttrs(ref d) => op(d).map(ItemAttrs),
FnArgNames(ref d) => op(d).map(FnArgNames),
+ TraitOfItem(ref d) => op(d).map(TraitOfItem),
ItemBodyNestedBodies(ref d) => op(d).map(ItemBodyNestedBodies),
ConstIsRvaluePromotableToStatic(ref d) => op(d).map(ConstIsRvaluePromotableToStatic),
IsMirAvailable(ref d) => op(d).map(IsMirAvailable),
fn impl_parent(&self, impl_def_id: DefId) -> Option<DefId>;
// trait/impl-item info
- fn trait_of_item(&self, def_id: DefId) -> Option<DefId>;
fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem;
// flags
fn impl_parent(&self, def: DefId) -> Option<DefId> { bug!("impl_parent") }
// trait/impl-item info
- fn trait_of_item(&self, def_id: DefId) -> Option<DefId> { bug!("trait_of_item") }
fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem
{ bug!("associated_item_cloned") }
}
}
+impl<'tcx> QueryDescription for queries::trait_of_item<'tcx> {
+ fn describe(_: TyCtxt, _: DefId) -> String {
+ bug!("trait_of_item")
+ }
+}
+
impl<'tcx> QueryDescription for queries::item_body_nested_bodies<'tcx> {
fn describe(tcx: TyCtxt, def_id: DefId) -> String {
format!("nested item bodies of `{}`", tcx.item_path_str(def_id))
[] deprecation: Deprecation(DefId) -> Option<attr::Deprecation>,
[] item_attrs: ItemAttrs(DefId) -> Rc<[ast::Attribute]>,
[] fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
+ [] trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
[] item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> Rc<BTreeMap<hir::BodyId, hir::Body>>,
[] const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
[] is_mir_available: IsMirAvailable(DefId) -> bool,
}
}
- /// If the given def ID describes an item belonging to a trait,
- /// return the ID of the trait that the trait item belongs to.
- /// Otherwise, return `None`.
- pub fn trait_of_item(self, def_id: DefId) -> Option<DefId> {
- if def_id.krate != LOCAL_CRATE {
- return self.sess.cstore.trait_of_item(def_id);
- }
- self.opt_associated_item(def_id)
- .and_then(|associated_item| {
- match associated_item.container {
- TraitContainer(def_id) => Some(def_id),
- ImplContainer(_) => None
- }
- })
- }
-
/// Construct a parameter environment suitable for static contexts or other contexts where there
/// are no free type/lifetime parameters in scope.
pub fn empty_parameter_environment(self) -> ParameterEnvironment<'tcx> {
tcx.hir.span_if_local(def_id).unwrap()
}
+/// If the given def ID describes an item belonging to a trait,
+/// return the ID of the trait that the trait item belongs to.
+/// Otherwise, return `None`.
+fn trait_of_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Option<DefId> {
+ if def_id.krate != LOCAL_CRATE {
+ return None
+ }
+ tcx.opt_associated_item(def_id)
+ .and_then(|associated_item| {
+ match associated_item.container {
+ TraitContainer(def_id) => Some(def_id),
+ ImplContainer(_) => None
+ }
+ })
+}
+
+
pub fn provide(providers: &mut ty::maps::Providers) {
*providers = ty::maps::Providers {
associated_item,
adt_sized_constraint,
adt_dtorck_constraint,
def_span,
+ trait_of_item,
..*providers
};
}
// constants, we only try to find the expression for a
// trait-associated const if the caller gives us the
// substitutions for the reference to it.
- if tcx.sess.cstore.trait_of_item(def_id).is_some() {
+ if tcx.trait_of_item(def_id).is_some() {
resolve_trait_associated_const(tcx, def_id, substs)
} else {
Some((def_id, substs))
// This is only used by rustdoc anyway, which shouldn't have
// incremental recompilation ever enabled.
fn_arg_names => { cdata.get_fn_arg_names(def_id.index) }
+ trait_of_item => { cdata.get_trait_of_item(def_id.index) }
item_body_nested_bodies => {
let map: BTreeMap<_, _> = cdata.entry(def_id.index).ast.into_iter().flat_map(|ast| {
ast.decode(cdata).nested_bodies.decode(cdata).map(|body| (body.id(), body))
self.get_crate_data(impl_def.krate).get_parent_impl(impl_def.index)
}
- fn trait_of_item(&self, def_id: DefId) -> Option<DefId> {
- self.dep_graph.read(DepNode::MetaData(def_id));
- self.get_crate_data(def_id.krate).get_trait_of_item(def_id.index)
- }
-
fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem
{
self.dep_graph.read(DepNode::MetaData(def));