about summary refs log tree commit diff
path: root/clippy_lints
diff options
context:
space:
mode:
authora-yossy <atsuya0930@yahoo.co.jp>2025-05-30 22:33:15 +0900
committera-yossy <atsuya0930@yahoo.co.jp>2025-05-30 23:53:23 +0900
commitbb19ae5e2b2bb5fe3fb426336d6f199d654f3746 (patch)
tree4458c903b089bba07bc298a4388f28f1fa23397b /clippy_lints
parent6275f5235a939832b972e3d32c9fbff107f0bb34 (diff)
downloadrust-bb19ae5e2b2bb5fe3fb426336d6f199d654f3746.tar.gz
rust-bb19ae5e2b2bb5fe3fb426336d6f199d654f3746.zip
[`explicit_deref_methods`]: do not lint on method chains
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)
     {