This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +15
-21
lines changed
compiler/rustc_middle/src Expand file tree Collapse file tree 3 files changed +15
-21
lines changed Original file line number Diff line number Diff line change @@ -735,17 +735,6 @@ impl<'hir> Map<'hir> {
735735 }
736736 }
737737
738- /// Returns the `OwnerId` of `id`'s nearest module parent, or `id` itself if no
739- /// module parent is in this map.
740- pub ( super ) fn get_module_parent_node ( self , hir_id : HirId ) -> OwnerId {
741- for ( def_id, node) in self . parent_owner_iter ( hir_id) {
742- if let OwnerNode :: Item ( & Item { kind : ItemKind :: Mod ( _) , .. } ) = node {
743- return def_id;
744- }
745- }
746- CRATE_OWNER_ID
747- }
748-
749738 /// When on an if expression, a match arm tail expression or a match arm, give back
750739 /// the enclosing `if` or `match` expression.
751740 ///
Original file line number Diff line number Diff line change @@ -102,7 +102,21 @@ impl<'tcx> TyCtxt<'tcx> {
102102 }
103103
104104 pub fn parent_module ( self , id : HirId ) -> LocalDefId {
105- self . parent_module_from_def_id ( id. owner . def_id )
105+ if !id. is_owner ( ) && self . def_kind ( id. owner ) == DefKind :: Mod {
106+ id. owner . def_id
107+ } else {
108+ self . parent_module_from_def_id ( id. owner . def_id )
109+ }
110+ }
111+
112+ pub fn parent_module_from_def_id ( self , mut id : LocalDefId ) -> LocalDefId {
113+ while let Some ( parent) = self . opt_local_parent ( id) {
114+ id = parent;
115+ if self . def_kind ( id) == DefKind :: Mod {
116+ break ;
117+ }
118+ }
119+ id
106120 }
107121
108122 pub fn impl_subject ( self , def_id : DefId ) -> EarlyBinder < ImplSubject < ' tcx > > {
@@ -120,10 +134,6 @@ impl<'tcx> TyCtxt<'tcx> {
120134}
121135
122136pub fn provide ( providers : & mut Providers ) {
123- providers. parent_module_from_def_id = |tcx, id| {
124- let hir = tcx. hir ( ) ;
125- hir. get_module_parent_node ( hir. local_def_id_to_hir_id ( id) ) . def_id
126- } ;
127137 providers. hir_crate_items = map:: hir_crate_items;
128138 providers. crate_hash = map:: crate_hash;
129139 providers. hir_module_items = map:: hir_module_items;
Original file line number Diff line number Diff line change @@ -398,11 +398,6 @@ rustc_queries! {
398398 desc { "computing `#[expect]`ed lints in this crate" }
399399 }
400400
401- query parent_module_from_def_id( key: LocalDefId ) -> LocalDefId {
402- eval_always
403- desc { |tcx| "getting the parent module of `{}`" , tcx. def_path_str( key) }
404- }
405-
406401 query expn_that_defined( key: DefId ) -> rustc_span:: ExpnId {
407402 desc { |tcx| "getting the expansion that defined `{}`" , tcx. def_path_str( key) }
408403 separate_provide_extern
You can’t perform that action at this time.
0 commit comments