Skip to content

Commit 43c2b00

Browse files
committed
Store TyCtxt instead of Map in some iterators.
1 parent f04bbc6 commit 43c2b00

File tree

1 file changed

+19
-19
lines changed
  • compiler/rustc_middle/src/hir

1 file changed

+19
-19
lines changed

compiler/rustc_middle/src/hir/map.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ pub struct Map<'hir> {
2929

3030
/// An iterator that walks up the ancestor tree of a given `HirId`.
3131
/// Constructed using `tcx.hir().parent_iter(hir_id)`.
32-
struct ParentHirIterator<'hir> {
32+
struct ParentHirIterator<'tcx> {
3333
current_id: HirId,
34-
map: Map<'hir>,
34+
tcx: TyCtxt<'tcx>,
3535
// Cache the current value of `hir_owner_nodes` to avoid repeatedly calling the same query for
3636
// the same owner, which will uselessly record many times the same query dependency.
37-
current_owner_nodes: Option<&'hir OwnerNodes<'hir>>,
37+
current_owner_nodes: Option<&'tcx OwnerNodes<'tcx>>,
3838
}
3939

40-
impl<'hir> ParentHirIterator<'hir> {
41-
fn new(map: Map<'hir>, current_id: HirId) -> ParentHirIterator<'hir> {
42-
ParentHirIterator { current_id, map, current_owner_nodes: None }
40+
impl<'tcx> ParentHirIterator<'tcx> {
41+
fn new(tcx: TyCtxt<'tcx>, current_id: HirId) -> ParentHirIterator<'tcx> {
42+
ParentHirIterator { current_id, tcx, current_owner_nodes: None }
4343
}
4444
}
4545

46-
impl<'hir> Iterator for ParentHirIterator<'hir> {
46+
impl<'tcx> Iterator for ParentHirIterator<'tcx> {
4747
type Item = HirId;
4848

4949
fn next(&mut self) -> Option<Self::Item> {
@@ -56,10 +56,10 @@ impl<'hir> Iterator for ParentHirIterator<'hir> {
5656
let parent_id = if local_id == ItemLocalId::ZERO {
5757
// We go from an owner to its parent, so clear the cache.
5858
self.current_owner_nodes = None;
59-
self.map.tcx.hir_owner_parent(owner)
59+
self.tcx.hir_owner_parent(owner)
6060
} else {
6161
let owner_nodes =
62-
self.current_owner_nodes.get_or_insert_with(|| self.map.tcx.hir_owner_nodes(owner));
62+
self.current_owner_nodes.get_or_insert_with(|| self.tcx.hir_owner_nodes(owner));
6363
let parent_local_id = owner_nodes.nodes[local_id].parent;
6464
// HIR indexing should have checked that.
6565
debug_assert_ne!(parent_local_id, local_id);
@@ -75,32 +75,32 @@ impl<'hir> Iterator for ParentHirIterator<'hir> {
7575

7676
/// An iterator that walks up the ancestor tree of a given `HirId`.
7777
/// Constructed using `tcx.hir().parent_owner_iter(hir_id)`.
78-
pub struct ParentOwnerIterator<'hir> {
78+
pub struct ParentOwnerIterator<'tcx> {
7979
current_id: HirId,
80-
map: Map<'hir>,
80+
tcx: TyCtxt<'tcx>,
8181
}
8282

83-
impl<'hir> Iterator for ParentOwnerIterator<'hir> {
84-
type Item = (OwnerId, OwnerNode<'hir>);
83+
impl<'tcx> Iterator for ParentOwnerIterator<'tcx> {
84+
type Item = (OwnerId, OwnerNode<'tcx>);
8585

8686
fn next(&mut self) -> Option<Self::Item> {
8787
if self.current_id.local_id.index() != 0 {
8888
self.current_id.local_id = ItemLocalId::ZERO;
89-
let node = self.map.tcx.hir_owner_node(self.current_id.owner);
89+
let node = self.tcx.hir_owner_node(self.current_id.owner);
9090
return Some((self.current_id.owner, node));
9191
}
9292
if self.current_id == CRATE_HIR_ID {
9393
return None;
9494
}
9595

96-
let parent_id = self.map.tcx.hir_def_key(self.current_id.owner.def_id).parent;
96+
let parent_id = self.tcx.hir_def_key(self.current_id.owner.def_id).parent;
9797
let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| {
9898
let def_id = LocalDefId { local_def_index };
99-
self.map.tcx.local_def_id_to_hir_id(def_id).owner
99+
self.tcx.local_def_id_to_hir_id(def_id).owner
100100
});
101101
self.current_id = HirId::make_owner(parent_id.def_id);
102102

103-
let node = self.map.tcx.hir_owner_node(self.current_id.owner);
103+
let node = self.tcx.hir_owner_node(self.current_id.owner);
104104
Some((self.current_id.owner, node))
105105
}
106106
}
@@ -505,7 +505,7 @@ impl<'hir> Map<'hir> {
505505
/// until the crate root is reached. Prefer this over your own loop using `parent_id`.
506506
#[inline]
507507
pub fn parent_id_iter(self, current_id: HirId) -> impl Iterator<Item = HirId> + 'hir {
508-
ParentHirIterator::new(self, current_id)
508+
ParentHirIterator::new(self.tcx, current_id)
509509
}
510510

511511
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
@@ -519,7 +519,7 @@ impl<'hir> Map<'hir> {
519519
/// until the crate root is reached. Prefer this over your own loop using `parent_id`.
520520
#[inline]
521521
pub fn parent_owner_iter(self, current_id: HirId) -> ParentOwnerIterator<'hir> {
522-
ParentOwnerIterator { current_id, map: self }
522+
ParentOwnerIterator { current_id, tcx: self.tcx }
523523
}
524524

525525
/// Checks if the node is left-hand side of an assignment.

0 commit comments

Comments
 (0)