File tree 3 files changed +15
-21
lines changed
compiler/rustc_middle/src
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> {
735
735
}
736
736
}
737
737
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
-
749
738
/// When on an if expression, a match arm tail expression or a match arm, give back
750
739
/// the enclosing `if` or `match` expression.
751
740
///
Original file line number Diff line number Diff line change @@ -102,7 +102,21 @@ impl<'tcx> TyCtxt<'tcx> {
102
102
}
103
103
104
104
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
106
120
}
107
121
108
122
pub fn impl_subject ( self , def_id : DefId ) -> EarlyBinder < ImplSubject < ' tcx > > {
@@ -120,10 +134,6 @@ impl<'tcx> TyCtxt<'tcx> {
120
134
}
121
135
122
136
pub 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
- } ;
127
137
providers. hir_crate_items = map:: hir_crate_items;
128
138
providers. crate_hash = map:: crate_hash;
129
139
providers. hir_module_items = map:: hir_module_items;
Original file line number Diff line number Diff line change @@ -398,11 +398,6 @@ rustc_queries! {
398
398
desc { "computing `#[expect]`ed lints in this crate" }
399
399
}
400
400
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
-
406
401
query expn_that_defined( key: DefId ) -> rustc_span:: ExpnId {
407
402
desc { |tcx| "getting the expansion that defined `{}`" , tcx. def_path_str( key) }
408
403
separate_provide_extern
You can’t perform that action at this time.
0 commit comments