@@ -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,24 @@ trait UnusedDelimLint {
710712 }
711713 }
712714
715+ // For method receivers, parentheses are necessary for certain expression types
716+ // to avoid parsing ambiguities, e.g. `(1..10).sum()`, `(*ptr).method()`, etc.
717+ // Also keep parens around blocks for readability.
718+ if ctx == UnusedDelimsCtx :: MethodReceiver {
719+ match inner. kind {
720+ ast:: ExprKind :: Range ( ..)
721+ | ast:: ExprKind :: Unary ( ..)
722+ | ast:: ExprKind :: Binary ( ..)
723+ | ast:: ExprKind :: Cast ( ..)
724+ | ast:: ExprKind :: Type ( ..)
725+ | ast:: ExprKind :: Assign ( ..)
726+ | ast:: ExprKind :: AssignOp ( ..)
727+ | ast:: ExprKind :: AddrOf ( ..)
728+ | ast:: ExprKind :: Block ( ..) => return true ,
729+ _ => { }
730+ }
731+ }
732+
713733 // Check it's range in LetScrutineeExpr
714734 if let ast:: ExprKind :: Range ( ..) = inner. kind
715735 && matches ! ( ctx, UnusedDelimsCtx :: LetScrutineeExpr )
@@ -976,13 +996,15 @@ trait UnusedDelimLint {
976996 }
977997 // either function/method call, or something this lint doesn't care about
978998 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 ) ,
999+ let ( args_to_check, ctx, receiver) = match * call_or_other {
1000+ Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg , None ) ,
1001+ MethodCall ( ref call) => {
1002+ ( & call. args [ ..] , UnusedDelimsCtx :: MethodArg , Some ( & call. receiver ) )
1003+ }
9821004 Closure ( ref closure)
9831005 if matches ! ( closure. fn_decl. output, FnRetTy :: Default ( _) ) =>
9841006 {
985- ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody )
1007+ ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody , None )
9861008 }
9871009 // actual catch-all arm
9881010 _ => {
@@ -999,6 +1021,17 @@ trait UnusedDelimLint {
9991021 for arg in args_to_check {
10001022 self . check_unused_delims_expr ( cx, arg, ctx, false , None , None , false ) ;
10011023 }
1024+ if let Some ( recv) = receiver {
1025+ self . check_unused_delims_expr (
1026+ cx,
1027+ recv,
1028+ UnusedDelimsCtx :: MethodReceiver ,
1029+ false ,
1030+ None ,
1031+ None ,
1032+ false ,
1033+ ) ;
1034+ }
10021035 return ;
10031036 }
10041037 } ;
0 commit comments