Skip to content

Commit 70f6c47

Browse files
get_parent and find_parent
1 parent bd1d897 commit 70f6c47

File tree

9 files changed

+14
-15
lines changed

9 files changed

+14
-15
lines changed

clippy_lints/src/escape.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool {
131131
_ => return false,
132132
}
133133

134-
matches!(map.find(map.parent_id(id)), Some(Node::Param(_)))
134+
matches!(map.find_parent(id), Some(Node::Param(_)))
135135
}
136136

137137
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
@@ -157,7 +157,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
157157
if is_argument(*map, cmt.hir_id) {
158158
// Skip closure arguments
159159
let parent_id = map.parent_id(cmt.hir_id);
160-
if let Some(Node::Expr(..)) = map.find(map.parent_id(parent_id)) {
160+
if let Some(Node::Expr(..)) = map.find_parent(parent_id) {
161161
return;
162162
}
163163

clippy_lints/src/manual_rem_euclid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid {
7474
&& let Some(hir_id) = path_to_local(expr3)
7575
&& let Some(Node::Pat(_)) = cx.tcx.hir().find(hir_id) {
7676
// Apply only to params or locals with annotated types
77-
match cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) {
77+
match cx.tcx.hir().find_parent(hir_id) {
7878
Some(Node::Param(..)) => (),
7979
Some(Node::Local(local)) => {
8080
let Some(ty) = local.ty else { return };

clippy_lints/src/matches/match_single_binding.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
140140
fn opt_parent_assign_span<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option<AssignmentExpr> {
141141
let map = &cx.tcx.hir();
142142

143-
if let Some(Node::Expr(parent_arm_expr)) = map.find(map.parent_id(ex.hir_id)) {
144-
return match map.find(map.parent_id(parent_arm_expr.hir_id)) {
143+
if let Some(Node::Expr(parent_arm_expr)) = map.find_parent(ex.hir_id) {
144+
return match map.find_parent(parent_arm_expr.hir_id) {
145145
Some(Node::Local(parent_let_expr)) => Some(AssignmentExpr::Local {
146146
span: parent_let_expr.span,
147147
pat_span: parent_let_expr.pat.span(),
@@ -183,8 +183,7 @@ fn sugg_with_curlies<'a>(
183183

184184
// If the parent is already an arm, and the body is another match statement,
185185
// we need curly braces around suggestion
186-
let parent_node_id = cx.tcx.hir().parent_id(match_expr.hir_id);
187-
if let Node::Arm(arm) = &cx.tcx.hir().get(parent_node_id) {
186+
if let Node::Arm(arm) = &cx.tcx.hir().get_parent(match_expr.hir_id) {
188187
if let ExprKind::Match(..) = arm.body.kind {
189188
cbrace_end = format!("\n{indent}}}");
190189
// Fix body indent due to the match

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
100100
}
101101

102102
// Exclude non-inherent impls
103-
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) {
103+
if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) {
104104
if matches!(
105105
item.kind,
106106
ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)

clippy_lints/src/pass_by_ref_or_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue {
299299
}
300300

301301
// Exclude non-inherent impls
302-
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) {
302+
if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) {
303303
if matches!(
304304
item.kind,
305305
ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)

clippy_lints/src/unit_types/unit_arg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
2121
return;
2222
}
2323
let map = &cx.tcx.hir();
24-
let opt_parent_node = map.find(map.parent_id(expr.hir_id));
24+
let opt_parent_node = map.find_parent(expr.hir_id);
2525
if_chain! {
2626
if let Some(hir::Node::Expr(parent_expr)) = opt_parent_node;
2727
if is_questionmark_desugar_marked_call(parent_expr);
@@ -192,7 +192,7 @@ fn fmt_stmts_and_call(
192192

193193
let mut stmts_and_call_snippet = stmts_and_call.join(&format!("{}{}", ";\n", " ".repeat(call_expr_indent)));
194194
// expr is not in a block statement or result expression position, wrap in a block
195-
let parent_node = cx.tcx.hir().find(cx.tcx.hir().parent_id(call_expr.hir_id));
195+
let parent_node = cx.tcx.hir().find_parent(call_expr.hir_id);
196196
if !matches!(parent_node, Some(Node::Block(_))) && !matches!(parent_node, Some(Node::Stmt(_))) {
197197
let block_indent = call_expr_indent + 4;
198198
stmts_and_call_snippet =

clippy_lints/src/unnecessary_wraps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
9191
}
9292

9393
// Abort if the method is implementing a trait or of it a trait method.
94-
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) {
94+
if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) {
9595
if matches!(
9696
item.kind,
9797
ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)

clippy_lints/src/utils/internal_lints/metadata_collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ fn get_parent_local<'hir>(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) -
10581058
fn get_parent_local_hir_id<'hir>(cx: &LateContext<'hir>, hir_id: hir::HirId) -> Option<&'hir hir::Local<'hir>> {
10591059
let map = cx.tcx.hir();
10601060

1061-
match map.find(map.parent_id(hir_id)) {
1061+
match map.find_parent((hir_id)) {
10621062
Some(hir::Node::Local(local)) => Some(local),
10631063
Some(hir::Node::Pat(pattern)) => get_parent_local_hir_id(cx, pattern.hir_id),
10641064
_ => None,

clippy_utils/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ pub fn contains_return(expr: &hir::Expr<'_>) -> bool {
12871287

12881288
/// Gets the parent node, if any.
12891289
pub fn get_parent_node(tcx: TyCtxt<'_>, id: HirId) -> Option<Node<'_>> {
1290-
tcx.hir().parent_iter(id).next().map(|(_, node)| node)
1290+
tcx.hir().find_parent(id)
12911291
}
12921292

12931293
/// Gets the parent expression, if any –- this is useful to constrain a lint.
@@ -2075,7 +2075,7 @@ pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool {
20752075
/// }
20762076
/// ```
20772077
pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool {
2078-
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) {
2078+
if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) {
20792079
matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }))
20802080
} else {
20812081
false

0 commit comments

Comments
 (0)