@@ -29,21 +29,21 @@ pub struct Map<'hir> {
29
29
30
30
/// An iterator that walks up the ancestor tree of a given `HirId`.
31
31
/// Constructed using `tcx.hir().parent_iter(hir_id)`.
32
- struct ParentHirIterator < ' hir > {
32
+ struct ParentHirIterator < ' tcx > {
33
33
current_id : HirId ,
34
- map : Map < ' hir > ,
34
+ tcx : TyCtxt < ' tcx > ,
35
35
// Cache the current value of `hir_owner_nodes` to avoid repeatedly calling the same query for
36
36
// 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 > > ,
38
38
}
39
39
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 }
43
43
}
44
44
}
45
45
46
- impl < ' hir > Iterator for ParentHirIterator < ' hir > {
46
+ impl < ' tcx > Iterator for ParentHirIterator < ' tcx > {
47
47
type Item = HirId ;
48
48
49
49
fn next ( & mut self ) -> Option < Self :: Item > {
@@ -56,10 +56,10 @@ impl<'hir> Iterator for ParentHirIterator<'hir> {
56
56
let parent_id = if local_id == ItemLocalId :: ZERO {
57
57
// We go from an owner to its parent, so clear the cache.
58
58
self . current_owner_nodes = None ;
59
- self . map . tcx . hir_owner_parent ( owner)
59
+ self . tcx . hir_owner_parent ( owner)
60
60
} else {
61
61
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) ) ;
63
63
let parent_local_id = owner_nodes. nodes [ local_id] . parent ;
64
64
// HIR indexing should have checked that.
65
65
debug_assert_ne ! ( parent_local_id, local_id) ;
@@ -75,32 +75,32 @@ impl<'hir> Iterator for ParentHirIterator<'hir> {
75
75
76
76
/// An iterator that walks up the ancestor tree of a given `HirId`.
77
77
/// Constructed using `tcx.hir().parent_owner_iter(hir_id)`.
78
- pub struct ParentOwnerIterator < ' hir > {
78
+ pub struct ParentOwnerIterator < ' tcx > {
79
79
current_id : HirId ,
80
- map : Map < ' hir > ,
80
+ tcx : TyCtxt < ' tcx > ,
81
81
}
82
82
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 > ) ;
85
85
86
86
fn next ( & mut self ) -> Option < Self :: Item > {
87
87
if self . current_id . local_id . index ( ) != 0 {
88
88
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 ) ;
90
90
return Some ( ( self . current_id . owner , node) ) ;
91
91
}
92
92
if self . current_id == CRATE_HIR_ID {
93
93
return None ;
94
94
}
95
95
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 ;
97
97
let parent_id = parent_id. map_or ( CRATE_OWNER_ID , |local_def_index| {
98
98
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
100
100
} ) ;
101
101
self . current_id = HirId :: make_owner ( parent_id. def_id ) ;
102
102
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 ) ;
104
104
Some ( ( self . current_id . owner , node) )
105
105
}
106
106
}
@@ -505,7 +505,7 @@ impl<'hir> Map<'hir> {
505
505
/// until the crate root is reached. Prefer this over your own loop using `parent_id`.
506
506
#[ inline]
507
507
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)
509
509
}
510
510
511
511
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
@@ -519,7 +519,7 @@ impl<'hir> Map<'hir> {
519
519
/// until the crate root is reached. Prefer this over your own loop using `parent_id`.
520
520
#[ inline]
521
521
pub fn parent_owner_iter ( self , current_id : HirId ) -> ParentOwnerIterator < ' hir > {
522
- ParentOwnerIterator { current_id, map : self }
522
+ ParentOwnerIterator { current_id, tcx : self . tcx }
523
523
}
524
524
525
525
/// Checks if the node is left-hand side of an assignment.
0 commit comments