about summary refs log tree commit diff
path: root/clippy_lints
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2025-05-30 15:02:47 +0000
committerGitHub <noreply@github.com>2025-05-30 15:02:47 +0000
commit010c2d3793db229ee139e26f08fc6600149a7afe (patch)
tree7c16e453ec0d02371f177cd9539f91d7cfdccaa2 /clippy_lints
parent10ec6fcfc52034053ece3f91c4727adb32832494 (diff)
parentbb19ae5e2b2bb5fe3fb426336d6f199d654f3746 (diff)
downloadrust-010c2d3793db229ee139e26f08fc6600149a7afe.tar.gz
rust-010c2d3793db229ee139e26f08fc6600149a7afe.zip
[`explicit_deref_methods`]: do not lint on method chains (#14921)
changelog: [`explicit_deref_methods`]: do not lint on method chains
fixes rust-lang/rust-clippy#14593
Diffstat (limited to 'clippy_lints')
-rw-r--r--clippy_lints/src/dereference.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs
index 8045926b1de..cde9528cd87 100644
--- a/clippy_lints/src/dereference.rs
+++ b/clippy_lints/src/dereference.rs
@@ -305,7 +305,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
                     RefOp::Method { mutbl, is_ufcs }
                         if !is_lint_allowed(cx, EXPLICIT_DEREF_METHODS, expr.hir_id)
                             // Allow explicit deref in method chains. e.g. `foo.deref().bar()`
-                            && (is_ufcs || !in_postfix_position(cx, expr)) =>
+                            && (is_ufcs || !is_in_method_chain(cx, expr)) =>
                     {
                         let ty_changed_count = usize::from(!deref_method_same_type(expr_ty, typeck.expr_ty(sub_expr)));
                         self.state = Some((
@@ -728,7 +728,13 @@ fn deref_method_same_type<'tcx>(result_ty: Ty<'tcx>, arg_ty: Ty<'tcx>) -> bool {
     }
 }
 
-fn in_postfix_position<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> bool {
+fn is_in_method_chain<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> bool {
+    if let ExprKind::MethodCall(_, recv, _, _) = e.kind
+        && matches!(recv.kind, ExprKind::MethodCall(..))
+    {
+        return true;
+    }
+
     if let Some(parent) = get_parent_expr(cx, e)
         && parent.span.eq_ctxt(e.span)
     {