Skip to content

Commit aab80ee

Browse files
committed
Extract get_fixed_offset_var from fetch_cloned_fixed_offset_var`
1 parent ecb472c commit aab80ee

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

clippy_lints/src/loops.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,16 @@ fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool {
828828
is_slice || is_type_diagnostic_item(cx, ty, sym!(vec_type)) || is_type_diagnostic_item(cx, ty, sym!(vecdeque_type))
829829
}
830830

831+
fn fetch_cloned_expr<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
832+
if_chain! {
833+
if let ExprKind::MethodCall(method, _, args) = expr.kind;
834+
if method.ident.name == sym!(clone);
835+
if args.len() == 1;
836+
if let Some(arg) = args.get(0);
837+
then { arg } else { expr }
838+
}
839+
}
840+
831841
fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>, var: HirId) -> Option<FixedOffsetVar> {
832842
fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr<'_>, var: HirId) -> Option<String> {
833843
match &e.kind {
@@ -875,24 +885,6 @@ fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>, v
875885
}
876886
}
877887

878-
fn fetch_cloned_fixed_offset_var<'a, 'tcx>(
879-
cx: &LateContext<'a, 'tcx>,
880-
expr: &Expr<'_>,
881-
var: HirId,
882-
) -> Option<FixedOffsetVar> {
883-
if_chain! {
884-
if let ExprKind::MethodCall(method, _, args) = expr.kind;
885-
if method.ident.name == sym!(clone);
886-
if args.len() == 1;
887-
if let Some(arg) = args.get(0);
888-
then {
889-
get_fixed_offset_var(cx, arg, var)
890-
} else {
891-
get_fixed_offset_var(cx, expr, var)
892-
}
893-
}
894-
}
895-
896888
fn get_indexed_assignments<'a, 'tcx>(
897889
cx: &LateContext<'a, 'tcx>,
898890
body: &Expr<'_>,
@@ -906,7 +898,7 @@ fn get_indexed_assignments<'a, 'tcx>(
906898
if let ExprKind::Assign(lhs, rhs, _) = e.kind {
907899
match (
908900
get_fixed_offset_var(cx, lhs, var),
909-
fetch_cloned_fixed_offset_var(cx, rhs, var),
901+
get_fixed_offset_var(cx, fetch_cloned_expr(rhs), var),
910902
) {
911903
(Some(offset_left), Some(offset_right)) => {
912904
// Source and destination must be different

0 commit comments

Comments
 (0)