@@ -11,6 +11,7 @@ private import rust
1111private import SsaImpl as SsaImpl
1212private import codeql.rust.controlflow.internal.Scope as Scope
1313private import codeql.rust.internal.PathResolution
14+ private import codeql.rust.internal.TypeInference as TypeInference
1415private import codeql.rust.controlflow.ControlFlowGraph
1516private import codeql.rust.controlflow.CfgNodes
1617private import codeql.rust.dataflow.Ssa
@@ -321,23 +322,6 @@ predicate lambdaCallExpr(CallExprCfgNode call, LambdaCallKind kind, ExprCfgNode
321322 exists ( kind )
322323}
323324
324- /** Holds if `mc` implicitly borrows its receiver. */
325- private predicate implicitBorrow ( MethodCallExpr mc ) {
326- // Determining whether an implicit borrow happens depends on the type of the
327- // receiever as well as the target. As a heuristic we simply check if the
328- // target takes `self` as a borrow and limit the approximation to cases where
329- // the receiver is a simple variable.
330- mc .getReceiver ( ) instanceof VariableAccess and
331- mc .getStaticTarget ( ) .getParamList ( ) .getSelfParam ( ) .isRef ( )
332- }
333-
334- /** Holds if `mc` implicitly dereferences its receiver. */
335- private predicate implicitDeref ( MethodCallExpr mc ) {
336- // Similarly to `implicitBorrow` this is an approximation.
337- mc .getReceiver ( ) instanceof VariableAccess and
338- not mc .getStaticTarget ( ) .getParamList ( ) .getSelfParam ( ) .isRef ( )
339- }
340-
341325// Defines a set of aliases needed for the `RustDataFlow` module
342326private module Aliases {
343327 class DataFlowCallableAlias = DataFlowCallable ;
@@ -520,15 +504,15 @@ module RustDataFlow implements InputSig<Location> {
520504
521505 pragma [ nomagic]
522506 private predicate implicitDerefToReceiver ( Node node1 , ReceiverNode node2 , ReferenceContent c ) {
507+ TypeInference:: receiverHasImplicitDeref ( node1 .asExpr ( ) .getExpr ( ) ) and
523508 node1 .asExpr ( ) = node2 .getReceiver ( ) and
524- implicitDeref ( node2 .getMethodCall ( ) .getMethodCallExpr ( ) ) and
525509 exists ( c )
526510 }
527511
528512 pragma [ nomagic]
529513 private predicate implicitBorrowToReceiver ( Node node1 , ReceiverNode node2 , ReferenceContent c ) {
514+ TypeInference:: receiverHasImplicitBorrow ( node1 .asExpr ( ) .getExpr ( ) ) and
530515 node1 .asExpr ( ) = node2 .getReceiver ( ) and
531- implicitBorrow ( node2 .getMethodCall ( ) .getMethodCallExpr ( ) ) and
532516 exists ( c )
533517 }
534518
0 commit comments