File tree 3 files changed +14
-2
lines changed
compiler/rustc_middle/src
3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -285,8 +285,7 @@ impl<'hir> Map<'hir> {
285
285
286
286
pub fn find_parent_node ( & self , id : HirId ) -> Option < HirId > {
287
287
if id. local_id == ItemLocalId :: from_u32 ( 0 ) {
288
- let index = self . tcx . index_hir ( LOCAL_CRATE ) ;
289
- index. parenting . get ( & id. owner ) . copied ( )
288
+ Some ( self . tcx . hir_owner_parent ( id. owner ) )
290
289
} else {
291
290
let owner = self . tcx . hir_owner_nodes ( id. owner ) ?;
292
291
let node = owner. nodes [ id. local_id ] . as_ref ( ) ?;
Original file line number Diff line number Diff line change @@ -129,6 +129,10 @@ pub fn provide(providers: &mut Providers) {
129
129
providers. hir_module_items = |tcx, id| & tcx. untracked_crate . modules [ & id] ;
130
130
providers. hir_owner = |tcx, id| tcx. index_hir ( LOCAL_CRATE ) . map [ id] . signature ;
131
131
providers. hir_owner_nodes = |tcx, id| tcx. index_hir ( LOCAL_CRATE ) . map [ id] . with_bodies . as_deref ( ) ;
132
+ providers. hir_owner_parent = |tcx, id| {
133
+ let index = tcx. index_hir ( LOCAL_CRATE ) ;
134
+ index. parenting . get ( & id) . copied ( ) . unwrap_or ( CRATE_HIR_ID )
135
+ } ;
132
136
providers. hir_attrs = |tcx, id| AttributeMap { map : & tcx. untracked_crate . attrs , prefix : id } ;
133
137
providers. def_span = |tcx, def_id| tcx. hir ( ) . span_if_local ( def_id) . unwrap_or ( DUMMY_SP ) ;
134
138
providers. fn_arg_names = |tcx, id| {
Original file line number Diff line number Diff line change @@ -52,6 +52,15 @@ rustc_queries! {
52
52
desc { |tcx| "HIR owner of `{}`" , tcx. def_path_str( key. to_def_id( ) ) }
53
53
}
54
54
55
+ /// Gives access to the HIR node's parent for the HIR owner `key`.
56
+ ///
57
+ /// This can be conveniently accessed by methods on `tcx.hir()`.
58
+ /// Avoid calling this query directly.
59
+ query hir_owner_parent( key: LocalDefId ) -> hir:: HirId {
60
+ eval_always
61
+ desc { |tcx| "HIR parent of `{}`" , tcx. def_path_str( key. to_def_id( ) ) }
62
+ }
63
+
55
64
/// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
56
65
///
57
66
/// This can be conveniently accessed by methods on `tcx.hir()`.
You can’t perform that action at this time.
0 commit comments