@@ -63,6 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for PathStatements {
6363enum UnusedDelimsCtx {
6464 FunctionArg ,
6565 MethodArg ,
66+ MethodReceiver ,
6667 AssignedValue ,
6768 AssignedValueLetElse ,
6869 IfCond ,
@@ -85,6 +86,7 @@ impl From<UnusedDelimsCtx> for &'static str {
8586 match ctx {
8687 UnusedDelimsCtx :: FunctionArg => "function argument" ,
8788 UnusedDelimsCtx :: MethodArg => "method argument" ,
89+ UnusedDelimsCtx :: MethodReceiver => "method receiver" ,
8890 UnusedDelimsCtx :: AssignedValue | UnusedDelimsCtx :: AssignedValueLetElse => {
8991 "assigned value"
9092 }
@@ -150,6 +152,16 @@ trait UnusedDelimLint {
150152 }
151153 }
152154
155+ // For method receivers, only lint simple path expressions like `(x).method()`.
156+ // Keep parens for all other cases to avoid false positives with complex expressions
157+ // like `(1..10).sum()`, `(*ptr).method()`, `({ block }).method()`, etc.
158+ // Only lint simple variable names like `(x).method()`
159+ if ctx == UnusedDelimsCtx :: MethodReceiver {
160+ if !matches ! ( inner. kind, ast:: ExprKind :: Path ( None , _) ) {
161+ return true ;
162+ }
163+ }
164+
153165 // Check it's range in LetScrutineeExpr
154166 if let ast:: ExprKind :: Range ( ..) = inner. kind
155167 && matches ! ( ctx, UnusedDelimsCtx :: LetScrutineeExpr )
@@ -417,13 +429,15 @@ trait UnusedDelimLint {
417429 }
418430 // either function/method call, or something this lint doesn't care about
419431 ref call_or_other => {
420- let ( args_to_check, ctx) = match * call_or_other {
421- Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg ) ,
422- MethodCall ( ref call) => ( & call. args [ ..] , UnusedDelimsCtx :: MethodArg ) ,
432+ let ( args_to_check, ctx, receiver) = match * call_or_other {
433+ Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg , None ) ,
434+ MethodCall ( ref call) => {
435+ ( & call. args [ ..] , UnusedDelimsCtx :: MethodArg , Some ( & call. receiver ) )
436+ }
423437 Closure ( ref closure)
424438 if matches ! ( closure. fn_decl. output, FnRetTy :: Default ( _) ) =>
425439 {
426- ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody )
440+ ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody , None )
427441 }
428442 // actual catch-all arm
429443 _ => {
@@ -440,6 +454,17 @@ trait UnusedDelimLint {
440454 for arg in args_to_check {
441455 self . check_unused_delims_expr ( cx, arg, ctx, false , None , None , false ) ;
442456 }
457+ if let Some ( recv) = receiver {
458+ self . check_unused_delims_expr (
459+ cx,
460+ recv,
461+ UnusedDelimsCtx :: MethodReceiver ,
462+ false ,
463+ None ,
464+ None ,
465+ false ,
466+ ) ;
467+ }
443468 return ;
444469 }
445470 } ;
@@ -1025,6 +1050,7 @@ impl UnusedDelimLint for UnusedBraces {
10251050 if let [ stmt] = inner. stmts . as_slice ( )
10261051 && let ast:: StmtKind :: Expr ( ref expr) = stmt. kind
10271052 && !Self :: is_expr_delims_necessary ( expr, ctx, followed_by_block)
1053+ && ctx != UnusedDelimsCtx :: MethodReceiver
10281054 && ( ctx != UnusedDelimsCtx :: AnonConst
10291055 || ( matches ! ( expr. kind, ast:: ExprKind :: Lit ( _) )
10301056 && !expr. span . from_expansion ( ) ) )
0 commit comments