@@ -133,21 +133,21 @@ private predicate callToMethod(CallExpr call) {
133133 )
134134}
135135
136- /** Holds if `arg` is an argument of `call` at the position `pos`. */
136+ /**
137+ * Holds if `arg` is an argument of `call` at the position `pos`.
138+ *
139+ * Note that this does not hold for the receiever expression of a method call
140+ * as the synthetic `ReceiverNode` is the argument for the `self` parameter.
141+ */
137142private predicate isArgumentForCall ( ExprCfgNode arg , CallExprBaseCfgNode call , ParameterPosition pos ) {
138143 if callToMethod ( call .( CallExprCfgNode ) .getCallExpr ( ) )
139- then (
144+ then
140145 // The first argument is for the `self` parameter
141146 arg = call .getArgument ( 0 ) and pos .isSelf ( )
142147 or
143148 // Succeeding arguments are shifted left
144149 arg = call .getArgument ( pos .getPosition ( ) + 1 )
145- ) else (
146- // The self argument in a method call.
147- arg = call .( MethodCallExprCfgNode ) .getReceiver ( ) and pos .isSelf ( )
148- or
149- arg = call .getArgument ( pos .getPosition ( ) )
150- )
150+ else arg = call .getArgument ( pos .getPosition ( ) )
151151}
152152
153153/**
@@ -370,19 +370,15 @@ module Node {
370370 private CallExprBaseCfgNode call_ ;
371371 private RustDataFlow:: ArgumentPosition pos_ ;
372372
373- ExprArgumentNode ( ) {
374- isArgumentForCall ( n , call_ , pos_ ) and
375- // For receivers in method calls the `ReceiverNode` is the argument.
376- not call_ .( MethodCallExprCfgNode ) .getReceiver ( ) = n
377- }
373+ ExprArgumentNode ( ) { isArgumentForCall ( n , call_ , pos_ ) }
378374
379375 override predicate isArgumentOf ( DataFlowCall call , RustDataFlow:: ArgumentPosition pos ) {
380376 call .asCallBaseExprCfgNode ( ) = call_ and pos = pos_
381377 }
382378 }
383379
384380 /**
385- * The receiver of a method call _after_ any implicit borrow or dereferences
381+ * The receiver of a method call _after_ any implicit borrow or dereferencing
386382 * has taken place.
387383 */
388384 final class ReceiverNode extends ArgumentNode , TReceiverNode {
@@ -400,7 +396,7 @@ module Node {
400396
401397 override CfgScope getCfgScope ( ) { result = n .getAstNode ( ) .getEnclosingCfgScope ( ) }
402398
403- override Location getLocation ( ) { result = n .getLocation ( ) }
399+ override Location getLocation ( ) { result = this . getReceiver ( ) .getLocation ( ) }
404400
405401 override string toString ( ) { result = "receiver for " + this .getReceiver ( ) }
406402 }
@@ -559,7 +555,7 @@ module Node {
559555
560556 override CfgScope getCfgScope ( ) { result = n .getAstNode ( ) .getEnclosingCfgScope ( ) }
561557
562- override Location getLocation ( ) { result = n .getLocation ( ) }
558+ override Location getLocation ( ) { result = n .getReceiver ( ) . getLocation ( ) }
563559 }
564560
565561 final class SummaryPostUpdateNode extends FlowSummaryNode , PostUpdateNode {
@@ -1050,7 +1046,7 @@ predicate lambdaCallExpr(CallExprCfgNode call, LambdaCallKind kind, ExprCfgNode
10501046}
10511047
10521048/** Holds if `mc` implicitly borrows its receiver. */
1053- predicate implicitBorrow ( MethodCallExpr mc ) {
1049+ private predicate implicitBorrow ( MethodCallExpr mc ) {
10541050 // Determining whether an implicit borrow happens depends on the type of the
10551051 // receiever as well as the target. As a heuristic we simply check if the
10561052 // target takes `self` as a borrow and limit the approximation to cases where
@@ -1060,7 +1056,7 @@ predicate implicitBorrow(MethodCallExpr mc) {
10601056}
10611057
10621058/** Holds if `mc` implicitly dereferences its receiver. */
1063- predicate implicitDeref ( MethodCallExpr mc ) {
1059+ private predicate implicitDeref ( MethodCallExpr mc ) {
10641060 // Similarly to `implicitBorrow` this is an approximation.
10651061 mc .getReceiver ( ) instanceof VariableAccess and
10661062 not mc .getStaticTarget ( ) .getParamList ( ) .getSelfParam ( ) .isRef ( )
@@ -1727,7 +1723,7 @@ private module Cached {
17271723 any ( IndexExprCfgNode i ) .getBase ( ) , any ( FieldExprCfgNode access ) .getExpr ( ) ,
17281724 any ( TryExprCfgNode try ) .getExpr ( ) ,
17291725 any ( PrefixExprCfgNode pe | pe .getOperatorName ( ) = "*" ) .getExpr ( ) ,
1730- any ( AwaitExprCfgNode a ) .getExpr ( )
1726+ any ( AwaitExprCfgNode a ) .getExpr ( ) , any ( MethodCallExprCfgNode mc ) . getReceiver ( )
17311727 ]
17321728 } or
17331729 TReceiverNode ( MethodCallExprCfgNode mc , Boolean isPost ) or
0 commit comments