@@ -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,15 @@ 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+ if ctx == UnusedDelimsCtx :: MethodReceiver {
719+ if !matches ! ( inner. kind, ast:: ExprKind :: Path ( ..) ) {
720+ return true ;
721+ }
722+ }
723+
713724 // Check it's range in LetScrutineeExpr
714725 if let ast:: ExprKind :: Range ( ..) = inner. kind
715726 && matches ! ( ctx, UnusedDelimsCtx :: LetScrutineeExpr )
@@ -976,13 +987,15 @@ trait UnusedDelimLint {
976987 }
977988 // either function/method call, or something this lint doesn't care about
978989 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 ) ,
990+ let ( args_to_check, ctx, receiver) = match * call_or_other {
991+ Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg , None ) ,
992+ MethodCall ( ref call) => {
993+ ( & call. args [ ..] , UnusedDelimsCtx :: MethodArg , Some ( & call. receiver ) )
994+ }
982995 Closure ( ref closure)
983996 if matches ! ( closure. fn_decl. output, FnRetTy :: Default ( _) ) =>
984997 {
985- ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody )
998+ ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody , None )
986999 }
9871000 // actual catch-all arm
9881001 _ => {
@@ -999,6 +1012,17 @@ trait UnusedDelimLint {
9991012 for arg in args_to_check {
10001013 self . check_unused_delims_expr ( cx, arg, ctx, false , None , None , false ) ;
10011014 }
1015+ if let Some ( recv) = receiver {
1016+ self . check_unused_delims_expr (
1017+ cx,
1018+ recv,
1019+ UnusedDelimsCtx :: MethodReceiver ,
1020+ false ,
1021+ None ,
1022+ None ,
1023+ false ,
1024+ ) ;
1025+ }
10021026 return ;
10031027 }
10041028 } ;
@@ -1584,6 +1608,7 @@ impl UnusedDelimLint for UnusedBraces {
15841608 if let [ stmt] = inner. stmts . as_slice ( )
15851609 && let ast:: StmtKind :: Expr ( ref expr) = stmt. kind
15861610 && !Self :: is_expr_delims_necessary ( expr, ctx, followed_by_block)
1611+ && ctx != UnusedDelimsCtx :: MethodReceiver
15871612 && ( ctx != UnusedDelimsCtx :: AnonConst
15881613 || ( matches ! ( expr. kind, ast:: ExprKind :: Lit ( _) )
15891614 && !expr. span . from_expansion ( ) ) )
0 commit comments