@@ -9,9 +9,11 @@ pub mod map;
99use crate :: ty:: query:: Providers ;
1010use crate :: ty:: TyCtxt ;
1111use rustc_data_structures:: fx:: FxHashMap ;
12+ use rustc_hir:: def_id:: DefId ;
1213use rustc_hir:: def_id:: LOCAL_CRATE ;
1314use rustc_hir:: print;
1415use rustc_hir:: Body ;
16+ use rustc_hir:: BodyId ;
1517use rustc_hir:: Crate ;
1618use rustc_hir:: HirId ;
1719use rustc_hir:: ItemLocalId ;
@@ -49,6 +51,14 @@ impl<'tcx> Hir<'tcx> {
4951 pub fn krate ( & self ) -> & ' tcx Crate < ' tcx > {
5052 self . tcx . hir_crate ( LOCAL_CRATE )
5153 }
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+ }
5262}
5363
5464impl < ' tcx > Deref for Hir < ' tcx > {
@@ -75,5 +85,13 @@ impl<'tcx> TyCtxt<'tcx> {
7585
7686pub fn provide ( providers : & mut Providers < ' _ > ) {
7787 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+ } ;
7896 map:: provide ( providers) ;
7997}
0 commit comments