@@ -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,22 @@ 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+ if ctx == UnusedDelimsCtx :: MethodReceiver {
718+ match inner. kind {
719+ ast:: ExprKind :: Range ( ..)
720+ | ast:: ExprKind :: Unary ( ..)
721+ | ast:: ExprKind :: Binary ( ..)
722+ | ast:: ExprKind :: Cast ( ..)
723+ | ast:: ExprKind :: Type ( ..)
724+ | ast:: ExprKind :: Assign ( ..)
725+ | ast:: ExprKind :: AssignOp ( ..)
726+ | ast:: ExprKind :: AddrOf ( ..) => return true ,
727+ _ => { }
728+ }
729+ }
730+
713731 // Check it's range in LetScrutineeExpr
714732 if let ast:: ExprKind :: Range ( ..) = inner. kind
715733 && matches ! ( ctx, UnusedDelimsCtx :: LetScrutineeExpr )
@@ -976,13 +994,15 @@ trait UnusedDelimLint {
976994 }
977995 // either function/method call, or something this lint doesn't care about
978996 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 ) ,
997+ let ( args_to_check, ctx, receiver) = match * call_or_other {
998+ Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg , None ) ,
999+ MethodCall ( ref call) => {
1000+ ( & call. args [ ..] , UnusedDelimsCtx :: MethodArg , Some ( & call. receiver ) )
1001+ }
9821002 Closure ( ref closure)
9831003 if matches ! ( closure. fn_decl. output, FnRetTy :: Default ( _) ) =>
9841004 {
985- ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody )
1005+ ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody , None )
9861006 }
9871007 // actual catch-all arm
9881008 _ => {
@@ -999,6 +1019,17 @@ trait UnusedDelimLint {
9991019 for arg in args_to_check {
10001020 self . check_unused_delims_expr ( cx, arg, ctx, false , None , None , false ) ;
10011021 }
1022+ if let Some ( recv) = receiver {
1023+ self . check_unused_delims_expr (
1024+ cx,
1025+ recv,
1026+ UnusedDelimsCtx :: MethodReceiver ,
1027+ false ,
1028+ None ,
1029+ None ,
1030+ false ,
1031+ ) ;
1032+ }
10021033 return ;
10031034 }
10041035 } ;
0 commit comments