Auto merge of #114516 - cjgillot:direct-module-parent, r=compiler-errors
parent_module_from_def_id does not need to be a query. r? `@ghost`
This commit is contained in:
commit
5973bfbd38
@ -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
|
||||
/// the enclosing `if` or `match` expression.
|
||||
///
|
||||
|
@ -102,7 +102,21 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
}
|
||||
|
||||
pub fn parent_module(self, id: HirId) -> LocalDefId {
|
||||
self.parent_module_from_def_id(id.owner.def_id)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
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>> {
|
||||
@ -120,10 +134,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
}
|
||||
|
||||
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.crate_hash = map::crate_hash;
|
||||
providers.hir_module_items = map::hir_module_items;
|
||||
|
@ -398,11 +398,6 @@ rustc_queries! {
|
||||
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 {
|
||||
desc { |tcx| "getting the expansion that defined `{}`", tcx.def_path_str(key) }
|
||||
separate_provide_extern
|
||||
|
Loading…
x
Reference in New Issue
Block a user