Skip to content

Commit 1e23449

Browse files
committed
Move is_receiver_of_method_call to clippy_utils for reuse
1 parent 4e7f974 commit 1e23449

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

clippy_lints/src/methods/search_is_some.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg};
22
use clippy_utils::source::{snippet, snippet_with_applicability};
33
use clippy_utils::sugg::deref_closure_args;
44
use clippy_utils::ty::is_type_lang_item;
5-
use clippy_utils::{get_parent_expr, is_trait_method, strip_pat_refs};
5+
use clippy_utils::{is_receiver_of_method_call, is_trait_method, strip_pat_refs};
66
use hir::ExprKind;
77
use rustc_errors::Applicability;
88
use rustc_hir as hir;
@@ -156,13 +156,3 @@ pub(super) fn check<'tcx>(
156156
}
157157
}
158158
}
159-
160-
fn is_receiver_of_method_call(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
161-
if let Some(parent_expr) = get_parent_expr(cx, expr)
162-
&& let ExprKind::MethodCall(_, receiver, ..) = parent_expr.kind
163-
&& receiver.hir_id == expr.hir_id
164-
{
165-
return true;
166-
}
167-
false
168-
}

clippy_utils/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3401,3 +3401,14 @@ pub fn binary_expr_needs_parentheses(expr: &Expr<'_>) -> bool {
34013401

34023402
contains_block(expr, false)
34033403
}
3404+
3405+
/// Returns true if the specified expression is in a receiver position.
3406+
pub fn is_receiver_of_method_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
3407+
if let Some(parent_expr) = get_parent_expr(cx, expr)
3408+
&& let ExprKind::MethodCall(_, receiver, ..) = parent_expr.kind
3409+
&& receiver.hir_id == expr.hir_id
3410+
{
3411+
return true;
3412+
}
3413+
false
3414+
}

0 commit comments

Comments
 (0)