@@ -643,20 +643,30 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
643643
644644 private import codeql.rust.elements.internal.CallExprImpl:: Impl as CallExprImpl
645645
646- class Access extends CallExprBase {
646+ abstract class Access extends Expr {
647+ abstract Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) ;
648+
649+ abstract AstNode getNodeAt ( AccessPosition apos ) ;
650+
651+ abstract Type getInferredType ( AccessPosition apos , TypePath path ) ;
652+
653+ abstract Declaration getTarget ( ) ;
654+ }
655+
656+ private class CallExprBaseAccess extends Access instanceof CallExprBase {
647657 private TypeMention getMethodTypeArg ( int i ) {
648658 result = this .( MethodCallExpr ) .getGenericArgList ( ) .getTypeArg ( i )
649659 }
650660
651- Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
661+ override Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
652662 exists ( TypeMention arg | result = arg .resolveTypeAt ( path ) |
653663 arg = getExplicitTypeArgMention ( CallExprImpl:: getFunctionPath ( this ) , apos .asTypeParam ( ) )
654664 or
655665 arg = this .getMethodTypeArg ( apos .asMethodTypeArgumentPosition ( ) )
656666 )
657667 }
658668
659- AstNode getNodeAt ( AccessPosition apos ) {
669+ override AstNode getNodeAt ( AccessPosition apos ) {
660670 exists ( int p , boolean isMethodCall |
661671 argPos ( this , result , p , isMethodCall ) and
662672 apos = TPositionalAccessPosition ( p , isMethodCall )
@@ -669,17 +679,42 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
669679 apos = TReturnAccessPosition ( )
670680 }
671681
672- Type getInferredType ( AccessPosition apos , TypePath path ) {
682+ override Type getInferredType ( AccessPosition apos , TypePath path ) {
673683 result = inferType ( this .getNodeAt ( apos ) , path )
674684 }
675685
676- Declaration getTarget ( ) {
686+ override Declaration getTarget ( ) {
677687 result = CallExprImpl:: getResolvedFunction ( this )
678688 or
679689 result = inferMethodCallTarget ( this ) // mutual recursion; resolving method calls requires resolving types and vice versa
680690 }
681691 }
682692
693+ private class OperationAccess extends Access instanceof Operation {
694+ OperationAccess ( ) { super .isOverloaded ( _, _) }
695+
696+ override Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
697+ // The syntax for operators does not allow type arguments.
698+ none ( )
699+ }
700+
701+ override AstNode getNodeAt ( AccessPosition apos ) {
702+ result = super .getOperand ( 0 ) and apos = TSelfAccessPosition ( )
703+ or
704+ result = super .getOperand ( 1 ) and apos = TPositionalAccessPosition ( 0 , true )
705+ or
706+ result = this and apos = TReturnAccessPosition ( )
707+ }
708+
709+ override Type getInferredType ( AccessPosition apos , TypePath path ) {
710+ result = inferType ( this .getNodeAt ( apos ) , path )
711+ }
712+
713+ override Declaration getTarget ( ) {
714+ result = inferMethodCallTarget ( this ) // mutual recursion; resolving method calls requires resolving types and vice versa
715+ }
716+ }
717+
683718 predicate accessDeclarationPositionMatch ( AccessPosition apos , DeclarationPosition dpos ) {
684719 apos .isSelf ( ) and
685720 dpos .isSelf ( )
@@ -1059,6 +1094,26 @@ private module MethodCall {
10591094 pragma [ nomagic]
10601095 override Type getTypeAt ( TypePath path ) { result = inferType ( receiver , path ) }
10611096 }
1097+
1098+ private class OperationMethodCall extends MethodCallImpl instanceof Operation {
1099+ TraitItemNode trait ;
1100+ string methodName ;
1101+
1102+ OperationMethodCall ( ) { super .isOverloaded ( trait , methodName ) }
1103+
1104+ override string getMethodName ( ) { result = methodName }
1105+
1106+ override int getArity ( ) { result = this .( Operation ) .getNumberOfOperands ( ) - 1 }
1107+
1108+ override Trait getTrait ( ) { result = trait }
1109+
1110+ pragma [ nomagic]
1111+ override Type getTypeAt ( TypePath path ) {
1112+ result = inferType ( this .( BinaryExpr ) .getLhs ( ) , path )
1113+ or
1114+ result = inferType ( this .( PrefixExpr ) .getExpr ( ) , path )
1115+ }
1116+ }
10621117}
10631118
10641119import MethodCall
0 commit comments