Skip to content

Commit c47a7e4

Browse files
committed
get_parent_node_by_hir_id -> get_parent_node
1 parent f0edfab commit c47a7e4

12 files changed

+17
-17
lines changed

clippy_lints/src/escape.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
115115
let map = &self.cx.tcx.hir();
116116
if map.is_argument(map.hir_to_node_id(consume_pat.hir_id)) {
117117
// Skip closure arguments
118-
if let Some(Node::Expr(..)) = map.find_by_hir_id(map.get_parent_node_by_hir_id(consume_pat.hir_id)) {
118+
if let Some(Node::Expr(..)) = map.find_by_hir_id(map.get_parent_node(consume_pat.hir_id)) {
119119
return;
120120
}
121121
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
@@ -124,7 +124,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
124124
return;
125125
}
126126
if let Categorization::Rvalue(..) = cmt.cat {
127-
if let Some(Node::Stmt(st)) = map.find_by_hir_id(map.get_parent_node_by_hir_id(cmt.hir_id)) {
127+
if let Some(Node::Stmt(st)) = map.find_by_hir_id(map.get_parent_node(cmt.hir_id)) {
128128
if let StmtKind::Local(ref loc) = st.node {
129129
if let Some(ref ex) = loc.init {
130130
if let ExprKind::Box(..) = ex.node {

clippy_lints/src/eval_order_dependence.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) {
176176
let map = &vis.cx.tcx.hir();
177177
let mut cur_id = vis.write_expr.hir_id;
178178
loop {
179-
let parent_id = map.get_parent_node_by_hir_id(cur_id);
179+
let parent_id = map.get_parent_node(cur_id);
180180
if parent_id == cur_id {
181181
break;
182182
}

clippy_lints/src/functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
110110
let is_impl = if let Some(hir::Node::Item(item)) = cx
111111
.tcx
112112
.hir()
113-
.find_by_hir_id(cx.tcx.hir().get_parent_node_by_hir_id(hir_id))
113+
.find_by_hir_id(cx.tcx.hir().get_parent_node(hir_id))
114114
{
115115
matches!(item.node, hir::ItemKind::Impl(_, _, _, _, Some(_), _, _))
116116
} else {

clippy_lints/src/loops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,7 @@ fn is_conditional(expr: &Expr) -> bool {
22182218
fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> bool {
22192219
if_chain! {
22202220
if let Some(loop_block) = get_enclosing_block(cx, match_expr.hir_id);
2221-
let parent_node = cx.tcx.hir().get_parent_node_by_hir_id(loop_block.hir_id);
2221+
let parent_node = cx.tcx.hir().get_parent_node(loop_block.hir_id);
22222222
if let Some(Node::Expr(loop_expr)) = cx.tcx.hir().find_by_hir_id(parent_node);
22232223
then {
22242224
return is_loop_nested(cx, loop_expr, iter_expr)
@@ -2235,7 +2235,7 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr)
22352235
return true;
22362236
};
22372237
loop {
2238-
let parent = cx.tcx.hir().get_parent_node_by_hir_id(id);
2238+
let parent = cx.tcx.hir().get_parent_node(id);
22392239
if parent == id {
22402240
return false;
22412241
}

clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
14231423
if cx.tables.expr_ty(arg) == ty {
14241424
snip = Some(("try removing the `clone` call", format!("{}", snippet)));
14251425
} else {
1426-
let parent = cx.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
1426+
let parent = cx.tcx.hir().get_parent_node(expr.hir_id);
14271427
match cx.tcx.hir().get(parent) {
14281428
hir::Node::Expr(parent) => match parent.node {
14291429
// &*x is a nop, &x.clone() is not

clippy_lints/src/needless_bool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
115115
}
116116

117117
fn parent_node_is_if_expr<'a, 'b>(expr: &Expr, cx: &LateContext<'a, 'b>) -> bool {
118-
let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
118+
let parent_id = cx.tcx.hir().get_parent_node(expr.hir_id);
119119
let parent_node = cx.tcx.hir().get(parent_id);
120120

121121
if let rustc::hir::Node::Expr(e) = parent_node {

clippy_lints/src/needless_pass_by_value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
9191
if let Some(Node::Item(item)) = cx
9292
.tcx
9393
.hir()
94-
.find_by_hir_id(cx.tcx.hir().get_parent_node_by_hir_id(hir_id))
94+
.find_by_hir_id(cx.tcx.hir().get_parent_node(hir_id))
9595
{
9696
if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
9797
ItemKind::Trait(..))
@@ -357,7 +357,7 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
357357
if let mc::Categorization::Local(vid) = cmt.cat {
358358
let mut id = matched_pat.hir_id;
359359
loop {
360-
let parent = self.cx.tcx.hir().get_parent_node_by_hir_id(id);
360+
let parent = self.cx.tcx.hir().get_parent_node(id);
361361
if id == parent {
362362
// no parent
363363
return;

clippy_lints/src/non_copy_const.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
169169

170170
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx ImplItem) {
171171
if let ImplItemKind::Const(hir_ty, ..) = &impl_item.node {
172-
let item_hir_id = cx.tcx.hir().get_parent_node_by_hir_id(impl_item.hir_id);
172+
let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id);
173173
let item = cx.tcx.hir().expect_item(item_hir_id);
174174
// Ensure the impl is an inherent impl.
175175
if let ItemKind::Impl(_, _, _, _, None, _, _) = item.node {
@@ -204,7 +204,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
204204
let mut dereferenced_expr = expr;
205205
let mut needs_check_adjustment = true;
206206
loop {
207-
let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(cur_expr.hir_id);
207+
let parent_id = cx.tcx.hir().get_parent_node(cur_expr.hir_id);
208208
if parent_id == cur_expr.hir_id {
209209
break;
210210
}

clippy_lints/src/suspicious_trait_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
6565
}
6666
// Check if the binary expression is part of another bi/unary expression
6767
// as a child node
68-
let mut parent_expr = cx.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
68+
let mut parent_expr = cx.tcx.hir().get_parent_node(expr.hir_id);
6969
while parent_expr != hir::CRATE_HIR_ID {
7070
if let hir::Node::Expr(e) = cx.tcx.hir().get(parent_expr) {
7171
match e.node {
@@ -75,7 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
7575
_ => {},
7676
}
7777
}
78-
parent_expr = cx.tcx.hir().get_parent_node_by_hir_id(parent_expr);
78+
parent_expr = cx.tcx.hir().get_parent_node(parent_expr);
7979
}
8080
// as a parent node
8181
let mut visitor = BinaryExprVisitor { in_binary_expr: false };

clippy_lints/src/trivially_copy_pass_by_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
182182
if let Some(Node::Item(item)) = cx
183183
.tcx
184184
.hir()
185-
.find_by_hir_id(cx.tcx.hir().get_parent_node_by_hir_id(hir_id))
185+
.find_by_hir_id(cx.tcx.hir().get_parent_node(hir_id))
186186
{
187187
if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
188188
ItemKind::Trait(..))

clippy_lints/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
585585
}
586586
if_chain! {
587587
let map = &cx.tcx.hir();
588-
let opt_parent_node = map.find_by_hir_id(map.get_parent_node_by_hir_id(expr.hir_id));
588+
let opt_parent_node = map.find_by_hir_id(map.get_parent_node(expr.hir_id));
589589
if let Some(hir::Node::Expr(parent_expr)) = opt_parent_node;
590590
if is_questionmark_desugar_marked_call(parent_expr);
591591
then {

clippy_lints/src/utils/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ fn trim_multiline_inner(s: Cow<'_, str>, ignore_first: bool, ch: char) -> Cow<'_
592592
pub fn get_parent_expr<'c>(cx: &'c LateContext<'_, '_>, e: &Expr) -> Option<&'c Expr> {
593593
let map = &cx.tcx.hir();
594594
let hir_id = e.hir_id;
595-
let parent_id = map.get_parent_node_by_hir_id(hir_id);
595+
let parent_id = map.get_parent_node(hir_id);
596596
if hir_id == parent_id {
597597
return None;
598598
}

0 commit comments

Comments
 (0)