Skip to content

Commit 30f3941

Browse files
committed
Move the body method
1 parent 8104bc4 commit 30f3941

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/librustc/hir/map/collector.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
208208
FxHashMap<DefIndex, &'hir mut HirOwnerItems<'hir>>,
209209
Svh,
210210
) {
211+
// Insert bodies into the map
212+
for (id, body) in self.krate.bodies.iter() {
213+
let bodies = &mut self.owner_items_map.get_mut(&id.hir_id.owner).unwrap().bodies;
214+
assert!(bodies.insert(id.hir_id.local_id, body).is_none());
215+
}
216+
211217
self.hir_body_nodes.sort_unstable_by_key(|bn| bn.0);
212218

213219
let node_hashes = self.hir_body_nodes.iter().fold(

src/librustc/hir/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ pub mod map;
99
use crate::ty::query::Providers;
1010
use crate::ty::TyCtxt;
1111
use rustc_data_structures::fx::FxHashMap;
12+
use rustc_hir::def_id::DefId;
1213
use rustc_hir::def_id::LOCAL_CRATE;
1314
use rustc_hir::print;
1415
use rustc_hir::Body;
16+
use rustc_hir::BodyId;
1517
use rustc_hir::Crate;
1618
use rustc_hir::HirId;
1719
use 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

5464
impl<'tcx> Deref for Hir<'tcx> {
@@ -75,5 +85,13 @@ impl<'tcx> TyCtxt<'tcx> {
7585

7686
pub 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

Comments
 (0)