parent_module_from_def_id does not need to be a query.
This commit is contained in:
parent
fbc11e9690
commit
7a51b30ebd
3 changed files with 15 additions and 21 deletions
|
@ -735,17 +735,6 @@ impl<'hir> Map<'hir> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `OwnerId` of `id`'s nearest module parent, or `id` itself if no
|
|
||||||
/// module parent is in this map.
|
|
||||||
pub(super) fn get_module_parent_node(self, hir_id: HirId) -> OwnerId {
|
|
||||||
for (def_id, node) in self.parent_owner_iter(hir_id) {
|
|
||||||
if let OwnerNode::Item(&Item { kind: ItemKind::Mod(_), .. }) = node {
|
|
||||||
return def_id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CRATE_OWNER_ID
|
|
||||||
}
|
|
||||||
|
|
||||||
/// When on an if expression, a match arm tail expression or a match arm, give back
|
/// When on an if expression, a match arm tail expression or a match arm, give back
|
||||||
/// the enclosing `if` or `match` expression.
|
/// the enclosing `if` or `match` expression.
|
||||||
///
|
///
|
||||||
|
|
|
@ -102,8 +102,22 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parent_module(self, id: HirId) -> LocalDefId {
|
pub fn parent_module(self, id: HirId) -> LocalDefId {
|
||||||
|
if !id.is_owner() && self.def_kind(id.owner) == DefKind::Mod {
|
||||||
|
id.owner.def_id
|
||||||
|
} else {
|
||||||
self.parent_module_from_def_id(id.owner.def_id)
|
self.parent_module_from_def_id(id.owner.def_id)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parent_module_from_def_id(self, mut id: LocalDefId) -> LocalDefId {
|
||||||
|
while let Some(parent) = self.opt_local_parent(id) {
|
||||||
|
id = parent;
|
||||||
|
if self.def_kind(id) == DefKind::Mod {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
id
|
||||||
|
}
|
||||||
|
|
||||||
pub fn impl_subject(self, def_id: DefId) -> EarlyBinder<ImplSubject<'tcx>> {
|
pub fn impl_subject(self, def_id: DefId) -> EarlyBinder<ImplSubject<'tcx>> {
|
||||||
match self.impl_trait_ref(def_id) {
|
match self.impl_trait_ref(def_id) {
|
||||||
|
@ -120,10 +134,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn provide(providers: &mut Providers) {
|
pub fn provide(providers: &mut Providers) {
|
||||||
providers.parent_module_from_def_id = |tcx, id| {
|
|
||||||
let hir = tcx.hir();
|
|
||||||
hir.get_module_parent_node(hir.local_def_id_to_hir_id(id)).def_id
|
|
||||||
};
|
|
||||||
providers.hir_crate_items = map::hir_crate_items;
|
providers.hir_crate_items = map::hir_crate_items;
|
||||||
providers.crate_hash = map::crate_hash;
|
providers.crate_hash = map::crate_hash;
|
||||||
providers.hir_module_items = map::hir_module_items;
|
providers.hir_module_items = map::hir_module_items;
|
||||||
|
|
|
@ -398,11 +398,6 @@ rustc_queries! {
|
||||||
desc { "computing `#[expect]`ed lints in this crate" }
|
desc { "computing `#[expect]`ed lints in this crate" }
|
||||||
}
|
}
|
||||||
|
|
||||||
query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
|
|
||||||
eval_always
|
|
||||||
desc { |tcx| "getting the parent module of `{}`", tcx.def_path_str(key) }
|
|
||||||
}
|
|
||||||
|
|
||||||
query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
|
query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
|
||||||
desc { |tcx| "getting the expansion that defined `{}`", tcx.def_path_str(key) }
|
desc { |tcx| "getting the expansion that defined `{}`", tcx.def_path_str(key) }
|
||||||
separate_provide_extern
|
separate_provide_extern
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue