Move is_receiver_of_method_call to clippy_utils for reuse

This commit is contained in:
Samuel Tardieu 2024-05-25 18:15:14 +02:00
parent 4e7f97467a
commit 1e23449678
2 changed files with 12 additions and 11 deletions

View File

@ -2,7 +2,7 @@
use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::source::{snippet, snippet_with_applicability};
use clippy_utils::sugg::deref_closure_args; use clippy_utils::sugg::deref_closure_args;
use clippy_utils::ty::is_type_lang_item; use clippy_utils::ty::is_type_lang_item;
use clippy_utils::{get_parent_expr, is_trait_method, strip_pat_refs}; use clippy_utils::{is_receiver_of_method_call, is_trait_method, strip_pat_refs};
use hir::ExprKind; use hir::ExprKind;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
@ -156,13 +156,3 @@ pub(super) fn check<'tcx>(
} }
} }
} }
fn is_receiver_of_method_call(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
if let Some(parent_expr) = get_parent_expr(cx, expr)
&& let ExprKind::MethodCall(_, receiver, ..) = parent_expr.kind
&& receiver.hir_id == expr.hir_id
{
return true;
}
false
}

View File

@ -3401,3 +3401,14 @@ fn contains_block(expr: &Expr<'_>, is_operand: bool) -> bool {
contains_block(expr, false) contains_block(expr, false)
} }
/// Returns true if the specified expression is in a receiver position.
pub fn is_receiver_of_method_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
if let Some(parent_expr) = get_parent_expr(cx, expr)
&& let ExprKind::MethodCall(_, receiver, ..) = parent_expr.kind
&& receiver.hir_id == expr.hir_id
{
return true;
}
false
}