@@ -623,6 +623,7 @@ impl<'tcx> LateLintPass<'tcx> for PathStatements {
623623enum UnusedDelimsCtx {
624624 FunctionArg ,
625625 MethodArg ,
626+ MethodReceiver ,
626627 AssignedValue ,
627628 AssignedValueLetElse ,
628629 IfCond ,
@@ -645,6 +646,7 @@ impl From<UnusedDelimsCtx> for &'static str {
645646 match ctx {
646647 UnusedDelimsCtx :: FunctionArg => "function argument" ,
647648 UnusedDelimsCtx :: MethodArg => "method argument" ,
649+ UnusedDelimsCtx :: MethodReceiver => "method receiver" ,
648650 UnusedDelimsCtx :: AssignedValue | UnusedDelimsCtx :: AssignedValueLetElse => {
649651 "assigned value"
650652 }
@@ -710,6 +712,16 @@ trait UnusedDelimLint {
710712 }
711713 }
712714
715+ // For method receivers, only lint simple path expressions like `(x).method()`.
716+ // Keep parens for all other cases to avoid false positives with complex expressions
717+ // like `(1..10).sum()`, `(*ptr).method()`, `({ block }).method()`, etc.
718+ // Only lint simple variable names like `(x).method()`
719+ if ctx == UnusedDelimsCtx :: MethodReceiver {
720+ if !matches ! ( inner. kind, ast:: ExprKind :: Path ( None , _) ) {
721+ return true ;
722+ }
723+ }
724+
713725 // Check it's range in LetScrutineeExpr
714726 if let ast:: ExprKind :: Range ( ..) = inner. kind
715727 && matches ! ( ctx, UnusedDelimsCtx :: LetScrutineeExpr )
@@ -976,13 +988,15 @@ trait UnusedDelimLint {
976988 }
977989 // either function/method call, or something this lint doesn't care about
978990 ref call_or_other => {
979- let ( args_to_check, ctx) = match * call_or_other {
980- Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg ) ,
981- MethodCall ( ref call) => ( & call. args [ ..] , UnusedDelimsCtx :: MethodArg ) ,
991+ let ( args_to_check, ctx, receiver) = match * call_or_other {
992+ Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg , None ) ,
993+ MethodCall ( ref call) => {
994+ ( & call. args [ ..] , UnusedDelimsCtx :: MethodArg , Some ( & call. receiver ) )
995+ }
982996 Closure ( ref closure)
983997 if matches ! ( closure. fn_decl. output, FnRetTy :: Default ( _) ) =>
984998 {
985- ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody )
999+ ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody , None )
9861000 }
9871001 // actual catch-all arm
9881002 _ => {
@@ -999,6 +1013,17 @@ trait UnusedDelimLint {
9991013 for arg in args_to_check {
10001014 self . check_unused_delims_expr ( cx, arg, ctx, false , None , None , false ) ;
10011015 }
1016+ if let Some ( recv) = receiver {
1017+ self . check_unused_delims_expr (
1018+ cx,
1019+ recv,
1020+ UnusedDelimsCtx :: MethodReceiver ,
1021+ false ,
1022+ None ,
1023+ None ,
1024+ false ,
1025+ ) ;
1026+ }
10021027 return ;
10031028 }
10041029 } ;
@@ -1584,6 +1609,7 @@ impl UnusedDelimLint for UnusedBraces {
15841609 if let [ stmt] = inner. stmts . as_slice ( )
15851610 && let ast:: StmtKind :: Expr ( ref expr) = stmt. kind
15861611 && !Self :: is_expr_delims_necessary ( expr, ctx, followed_by_block)
1612+ && ctx != UnusedDelimsCtx :: MethodReceiver
15871613 && ( ctx != UnusedDelimsCtx :: AnonConst
15881614 || ( matches ! ( expr. kind, ast:: ExprKind :: Lit ( _) )
15891615 && !expr. span . from_expansion ( ) ) )
0 commit comments