Skip to content

Commit 9f50c87

Browse files
authored
Rollup merge of rust-lang#89078 - camsteffen:map-ref, r=cjgillot
Cleanup: Remove needless reference in ParentHirIterator It forces an intermediate binding of `Map` which is a Copy type.
2 parents 051168b + 7c8f4f7 commit 9f50c87

File tree

4 files changed

+15
-22
lines changed

4 files changed

+15
-22
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ pub struct Map<'hir> {
8383

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

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

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

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

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

126126
fn next(&mut self) -> Option<Self::Item> {
@@ -588,13 +588,13 @@ impl<'hir> Map<'hir> {
588588

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

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

compiler/rustc_resolve/src/late/lifetimes.rs

+1-2
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

+1-2
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

+5-10
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)