diff options
| author | bors <bors@rust-lang.org> | 2023-08-06 18:04:04 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-08-06 18:04:04 +0000 |
| commit | 5973bfbd38fcefb63090a588733931e933498dfd (patch) | |
| tree | 08eb9b77715de7017b81537b9cd7b7b249ed701a | |
| parent | e59540968e0c6fc3c37d92a639b83fc8fcee5e81 (diff) | |
| parent | 7a51b30ebdc7a56d38a10b1d42e30c37857c33a9 (diff) | |
| download | rust-5973bfbd38fcefb63090a588733931e933498dfd.tar.gz rust-5973bfbd38fcefb63090a588733931e933498dfd.zip | |
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`
| -rw-r--r-- | compiler/rustc_middle/src/hir/map/mod.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/hir/mod.rs | 20 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/query/mod.rs | 5 |
3 files changed, 15 insertions, 21 deletions
diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 0256e09e4b5..2aebb8f541f 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -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. /// diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 45a07fdd293..06b25556c82 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -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; diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 35fe6ab99fb..533c3b66cab 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -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 |
