Skip to content

Commit 7c8f4f7

Browse files
committed
Remove needless hir Map ref
1 parent 35c8f26 commit 7c8f4f7

File tree

4 files changed

+15
-22
lines changed

4 files changed

+15
-22
lines changed

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ pub struct Map<'hir> {
8282

8383
/// An iterator that walks up the ancestor tree of a given `HirId`.
8484
/// Constructed using `tcx.hir().parent_iter(hir_id)`.
85-
pub struct ParentHirIterator<'map, 'hir> {
85+
pub struct ParentHirIterator<'hir> {
8686
current_id: HirId,
87-
map: &'map Map<'hir>,
87+
map: Map<'hir>,
8888
}
8989

90-
impl<'hir> Iterator for ParentHirIterator<'_, 'hir> {
90+
impl<'hir> Iterator for ParentHirIterator<'hir> {
9191
type Item = (HirId, Node<'hir>);
9292

9393
fn next(&mut self) -> Option<Self::Item> {
@@ -114,12 +114,12 @@ impl<'hir> Iterator for ParentHirIterator<'_, 'hir> {
114114

115115
/// An iterator that walks up the ancestor tree of a given `HirId`.
116116
/// Constructed using `tcx.hir().parent_owner_iter(hir_id)`.
117-
pub struct ParentOwnerIterator<'map, 'hir> {
117+
pub struct ParentOwnerIterator<'hir> {
118118
current_id: HirId,
119-
map: &'map Map<'hir>,
119+
map: Map<'hir>,
120120
}
121121

122-
impl<'hir> Iterator for ParentOwnerIterator<'_, 'hir> {
122+
impl<'hir> Iterator for ParentOwnerIterator<'hir> {
123123
type Item = (HirId, OwnerNode<'hir>);
124124

125125
fn next(&mut self) -> Option<Self::Item> {
@@ -560,13 +560,13 @@ impl<'hir> Map<'hir> {
560560

561561
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
562562
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
563-
pub fn parent_iter(&self, current_id: HirId) -> ParentHirIterator<'_, 'hir> {
563+
pub fn parent_iter(self, current_id: HirId) -> ParentHirIterator<'hir> {
564564
ParentHirIterator { current_id, map: self }
565565
}
566566

567567
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
568568
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
569-
pub fn parent_owner_iter(&self, current_id: HirId) -> ParentOwnerIterator<'_, 'hir> {
569+
pub fn parent_owner_iter(self, current_id: HirId) -> ParentOwnerIterator<'hir> {
570570
ParentOwnerIterator { current_id, map: self }
571571
}
572572

compiler/rustc_resolve/src/late/lifetimes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,7 @@ fn item_for(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> LocalDefId {
522522
_ => {}
523523
}
524524
let item = {
525-
let hir = tcx.hir();
526-
let mut parent_iter = hir.parent_iter(hir_id);
525+
let mut parent_iter = tcx.hir().parent_iter(hir_id);
527526
loop {
528527
let node = parent_iter.next().map(|n| n.1);
529528
match node {

src/tools/clippy/clippy_utils/src/higher.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ impl<'hir> IfLet<'hir> {
105105
if_else,
106106
) = expr.kind
107107
{
108-
let hir = cx.tcx.hir();
109-
let mut iter = hir.parent_iter(expr.hir_id);
108+
let mut iter = cx.tcx.hir().parent_iter(expr.hir_id);
110109
if let Some((_, Node::Block(Block { stmts: [], .. }))) = iter.next() {
111110
if let Some((
112111
_,

src/tools/clippy/clippy_utils/src/lib.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -833,12 +833,11 @@ pub fn capture_local_usage(cx: &LateContext<'tcx>, e: &Expr<'_>) -> CaptureKind
833833
ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(_), .. }))
834834
));
835835

836-
let map = cx.tcx.hir();
837836
let mut child_id = e.hir_id;
838837
let mut capture = CaptureKind::Value;
839838
let mut capture_expr_ty = e;
840839

841-
for (parent_id, parent) in map.parent_iter(e.hir_id) {
840+
for (parent_id, parent) in cx.tcx.hir().parent_iter(e.hir_id) {
842841
if let [Adjustment {
843842
kind: Adjust::Deref(_) | Adjust::Borrow(AutoBorrow::Ref(..)),
844843
target,
@@ -1224,8 +1223,7 @@ pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio
12241223

12251224
/// Gets the loop or closure enclosing the given expression, if any.
12261225
pub fn get_enclosing_loop_or_closure(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
1227-
let map = tcx.hir();
1228-
for (_, node) in map.parent_iter(expr.hir_id) {
1226+
for (_, node) in tcx.hir().parent_iter(expr.hir_id) {
12291227
match node {
12301228
Node::Expr(
12311229
e
@@ -1244,8 +1242,7 @@ pub fn get_enclosing_loop_or_closure(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Opti
12441242

12451243
/// Gets the parent node if it's an impl block.
12461244
pub fn get_parent_as_impl(tcx: TyCtxt<'_>, id: HirId) -> Option<&Impl<'_>> {
1247-
let map = tcx.hir();
1248-
match map.parent_iter(id).next() {
1245+
match tcx.hir().parent_iter(id).next() {
12491246
Some((
12501247
_,
12511248
Node::Item(Item {
@@ -1259,8 +1256,7 @@ pub fn get_parent_as_impl(tcx: TyCtxt<'_>, id: HirId) -> Option<&Impl<'_>> {
12591256

12601257
/// Checks if the given expression is the else clause of either an `if` or `if let` expression.
12611258
pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
1262-
let map = tcx.hir();
1263-
let mut iter = map.parent_iter(expr.hir_id);
1259+
let mut iter = tcx.hir().parent_iter(expr.hir_id);
12641260
match iter.next() {
12651261
Some((
12661262
_,
@@ -1794,9 +1790,8 @@ pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool
17941790

17951791
/// Gets the node where an expression is either used, or it's type is unified with another branch.
17961792
pub fn get_expr_use_or_unification_node(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Option<Node<'tcx>> {
1797-
let map = tcx.hir();
17981793
let mut child_id = expr.hir_id;
1799-
let mut iter = map.parent_iter(child_id);
1794+
let mut iter = tcx.hir().parent_iter(child_id);
18001795
loop {
18011796
match iter.next() {
18021797
None => break None,

0 commit comments

Comments
 (0)