@@ -9,9 +9,11 @@ pub mod map;
9
9
use crate :: ty:: query:: Providers ;
10
10
use crate :: ty:: TyCtxt ;
11
11
use rustc_data_structures:: fx:: FxHashMap ;
12
+ use rustc_hir:: def_id:: DefId ;
12
13
use rustc_hir:: def_id:: LOCAL_CRATE ;
13
14
use rustc_hir:: print;
14
15
use rustc_hir:: Body ;
16
+ use rustc_hir:: BodyId ;
15
17
use rustc_hir:: Crate ;
16
18
use rustc_hir:: HirId ;
17
19
use rustc_hir:: ItemLocalId ;
@@ -49,6 +51,14 @@ impl<'tcx> Hir<'tcx> {
49
51
pub fn krate ( & self ) -> & ' tcx Crate < ' tcx > {
50
52
self . tcx . hir_crate ( LOCAL_CRATE )
51
53
}
54
+
55
+ pub fn body ( & self , id : BodyId ) -> & ' tcx Body < ' tcx > {
56
+ self . tcx
57
+ . hir_owner_items ( DefId :: local ( id. hir_id . owner ) )
58
+ . bodies
59
+ . get ( & id. hir_id . local_id )
60
+ . unwrap ( )
61
+ }
52
62
}
53
63
54
64
impl < ' tcx > Deref for Hir < ' tcx > {
@@ -75,5 +85,13 @@ impl<'tcx> TyCtxt<'tcx> {
75
85
76
86
pub fn provide ( providers : & mut Providers < ' _ > ) {
77
87
providers. hir_crate = |tcx, _| tcx. hir_map . untracked_krate ( ) ;
88
+ providers. hir_owner = |tcx, id| {
89
+ assert_eq ! ( id. krate, LOCAL_CRATE ) ;
90
+ * tcx. hir_map . owner_map . get ( & id. index ) . unwrap ( )
91
+ } ;
92
+ providers. hir_owner_items = |tcx, id| {
93
+ assert_eq ! ( id. krate, LOCAL_CRATE ) ;
94
+ * tcx. hir_map . owner_items_map . get ( & id. index ) . unwrap ( )
95
+ } ;
78
96
map:: provide ( providers) ;
79
97
}
0 commit comments