about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/methods/mod.rs4
-rw-r--r--clippy_lints/src/useless_conversion.rs53
2 files changed, 27 insertions, 30 deletions
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index be75178dcc8..bcd54557331 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -5286,10 +5286,6 @@ impl Methods {
                     }
                     map_identity::check(cx, expr, recv, m_arg, name, span);
                     manual_inspect::check(cx, expr, m_arg, name, span, self.msrv);
-                    crate::useless_conversion::check_function_application(cx, expr, recv, m_arg);
-                },
-                (sym::map_break | sym::map_continue, [m_arg]) => {
-                    crate::useless_conversion::check_function_application(cx, expr, recv, m_arg);
                 },
                 (sym::map_or, [def, map]) => {
                     option_map_or_none::check(cx, expr, recv, def, map);
diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs
index 380ddea4e1e..e5b20c0e0a1 100644
--- a/clippy_lints/src/useless_conversion.rs
+++ b/clippy_lints/src/useless_conversion.rs
@@ -176,6 +176,33 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
                 }
             },
 
+            ExprKind::MethodCall(path, recv, [arg], _) => {
+                if matches!(
+                    path.ident.name,
+                    sym::map | sym::map_err | sym::map_break | sym::map_continue
+                ) && has_eligible_receiver(cx, recv, e)
+                    && (is_trait_item(cx, arg, sym::Into) || is_trait_item(cx, arg, sym::From))
+                    && let ty::FnDef(_, args) = cx.typeck_results().expr_ty(arg).kind()
+                    && let &[from_ty, to_ty] = args.into_type_list(cx.tcx).as_slice()
+                    && same_type_and_consts(from_ty, to_ty)
+                {
+                    span_lint_and_then(
+                        cx,
+                        USELESS_CONVERSION,
+                        e.span.with_lo(recv.span.hi()),
+                        format!("useless conversion to the same type: `{from_ty}`"),
+                        |diag| {
+                            diag.suggest_remove_item(
+                                cx,
+                                e.span.with_lo(recv.span.hi()),
+                                "consider removing",
+                                Applicability::MachineApplicable,
+                            );
+                        },
+                    );
+                }
+            },
+
             ExprKind::MethodCall(name, recv, [], _) => {
                 if is_trait_method(cx, e, sym::Into) && name.ident.name == sym::into {
                     let a = cx.typeck_results().expr_ty(e);
@@ -412,32 +439,6 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
     }
 }
 
-/// Check if `arg` is a `Into::into` or `From::from` applied to `receiver` to give `expr`, through a
-/// higher-order mapping function.
-pub fn check_function_application(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Expr<'_>) {
-    if has_eligible_receiver(cx, recv, expr)
-        && (is_trait_item(cx, arg, sym::Into) || is_trait_item(cx, arg, sym::From))
-        && let ty::FnDef(_, args) = cx.typeck_results().expr_ty(arg).kind()
-        && let &[from_ty, to_ty] = args.into_type_list(cx.tcx).as_slice()
-        && same_type_and_consts(from_ty, to_ty)
-    {
-        span_lint_and_then(
-            cx,
-            USELESS_CONVERSION,
-            expr.span.with_lo(recv.span.hi()),
-            format!("useless conversion to the same type: `{from_ty}`"),
-            |diag| {
-                diag.suggest_remove_item(
-                    cx,
-                    expr.span.with_lo(recv.span.hi()),
-                    "consider removing",
-                    Applicability::MachineApplicable,
-                );
-            },
-        );
-    }
-}
-
 fn has_eligible_receiver(cx: &LateContext<'_>, recv: &Expr<'_>, expr: &Expr<'_>) -> bool {
     if is_inherent_method_call(cx, expr) {
         matches!(