@@ -133,21 +133,21 @@ private predicate callToMethod(CallExpr call) {
133
133
)
134
134
}
135
135
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
+ */
137
142
private predicate isArgumentForCall ( ExprCfgNode arg , CallExprBaseCfgNode call , ParameterPosition pos ) {
138
143
if callToMethod ( call .( CallExprCfgNode ) .getCallExpr ( ) )
139
- then (
144
+ then
140
145
// The first argument is for the `self` parameter
141
146
arg = call .getArgument ( 0 ) and pos .isSelf ( )
142
147
or
143
148
// Succeeding arguments are shifted left
144
149
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 ( ) )
151
151
}
152
152
153
153
/**
@@ -370,19 +370,15 @@ module Node {
370
370
private CallExprBaseCfgNode call_ ;
371
371
private RustDataFlow:: ArgumentPosition pos_ ;
372
372
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_ ) }
378
374
379
375
override predicate isArgumentOf ( DataFlowCall call , RustDataFlow:: ArgumentPosition pos ) {
380
376
call .asCallBaseExprCfgNode ( ) = call_ and pos = pos_
381
377
}
382
378
}
383
379
384
380
/**
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
386
382
* has taken place.
387
383
*/
388
384
final class ReceiverNode extends ArgumentNode , TReceiverNode {
@@ -400,7 +396,7 @@ module Node {
400
396
401
397
override CfgScope getCfgScope ( ) { result = n .getAstNode ( ) .getEnclosingCfgScope ( ) }
402
398
403
- override Location getLocation ( ) { result = n .getLocation ( ) }
399
+ override Location getLocation ( ) { result = this . getReceiver ( ) .getLocation ( ) }
404
400
405
401
override string toString ( ) { result = "receiver for " + this .getReceiver ( ) }
406
402
}
@@ -559,7 +555,7 @@ module Node {
559
555
560
556
override CfgScope getCfgScope ( ) { result = n .getAstNode ( ) .getEnclosingCfgScope ( ) }
561
557
562
- override Location getLocation ( ) { result = n .getLocation ( ) }
558
+ override Location getLocation ( ) { result = n .getReceiver ( ) . getLocation ( ) }
563
559
}
564
560
565
561
final class SummaryPostUpdateNode extends FlowSummaryNode , PostUpdateNode {
@@ -1050,7 +1046,7 @@ predicate lambdaCallExpr(CallExprCfgNode call, LambdaCallKind kind, ExprCfgNode
1050
1046
}
1051
1047
1052
1048
/** Holds if `mc` implicitly borrows its receiver. */
1053
- predicate implicitBorrow ( MethodCallExpr mc ) {
1049
+ private predicate implicitBorrow ( MethodCallExpr mc ) {
1054
1050
// Determining whether an implicit borrow happens depends on the type of the
1055
1051
// receiever as well as the target. As a heuristic we simply check if the
1056
1052
// target takes `self` as a borrow and limit the approximation to cases where
@@ -1060,7 +1056,7 @@ predicate implicitBorrow(MethodCallExpr mc) {
1060
1056
}
1061
1057
1062
1058
/** Holds if `mc` implicitly dereferences its receiver. */
1063
- predicate implicitDeref ( MethodCallExpr mc ) {
1059
+ private predicate implicitDeref ( MethodCallExpr mc ) {
1064
1060
// Similarly to `implicitBorrow` this is an approximation.
1065
1061
mc .getReceiver ( ) instanceof VariableAccess and
1066
1062
not mc .getStaticTarget ( ) .getParamList ( ) .getSelfParam ( ) .isRef ( )
@@ -1727,7 +1723,7 @@ private module Cached {
1727
1723
any ( IndexExprCfgNode i ) .getBase ( ) , any ( FieldExprCfgNode access ) .getExpr ( ) ,
1728
1724
any ( TryExprCfgNode try ) .getExpr ( ) ,
1729
1725
any ( PrefixExprCfgNode pe | pe .getOperatorName ( ) = "*" ) .getExpr ( ) ,
1730
- any ( AwaitExprCfgNode a ) .getExpr ( )
1726
+ any ( AwaitExprCfgNode a ) .getExpr ( ) , any ( MethodCallExprCfgNode mc ) . getReceiver ( )
1731
1727
]
1732
1728
} or
1733
1729
TReceiverNode ( MethodCallExprCfgNode mc , Boolean isPost ) or
0 commit comments