@@ -796,65 +796,6 @@ private module MethodCallExprMatchingInput implements MatchingWithStateInputSig
796796 }
797797 }
798798
799- abstract additional class TupleDeclaration extends Declaration {
800- override Type getDeclaredType ( DeclarationPosition dpos , TypePath path ) {
801- result = super .getDeclaredType ( dpos , path )
802- or
803- dpos .isSelf ( ) and
804- result = this .getReturnType ( path )
805- }
806- }
807-
808- private class TupleStructDecl extends TupleDeclaration , Struct {
809- TupleStructDecl ( ) { this .isTuple ( ) }
810-
811- override TypeParameter getTypeParameter ( TypeParameterPosition ppos ) {
812- typeParamMatchPosition ( this .getGenericParamList ( ) .getATypeParam ( ) , result , ppos )
813- }
814-
815- override Type getParameterType ( DeclarationPosition dpos , TypePath path ) {
816- exists ( int pos |
817- result = this .getTupleField ( pos ) .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path ) and
818- pos = dpos .asPosition ( )
819- )
820- }
821-
822- override Type getReturnType ( TypePath path ) {
823- result = TStruct ( this ) and
824- path .isEmpty ( )
825- or
826- result = TTypeParamTypeParameter ( this .getGenericParamList ( ) .getATypeParam ( ) ) and
827- path = TypePath:: singleton ( result )
828- }
829- }
830-
831- private class TupleVariantDecl extends TupleDeclaration , Variant {
832- TupleVariantDecl ( ) { this .isTuple ( ) }
833-
834- override TypeParameter getTypeParameter ( TypeParameterPosition ppos ) {
835- typeParamMatchPosition ( this .getEnum ( ) .getGenericParamList ( ) .getATypeParam ( ) , result , ppos )
836- }
837-
838- override Type getParameterType ( DeclarationPosition dpos , TypePath path ) {
839- exists ( int pos |
840- result = this .getTupleField ( pos ) .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path ) and
841- pos = dpos .asPosition ( )
842- )
843- }
844-
845- override Type getReturnType ( TypePath path ) {
846- exists ( Enum enum | enum = this .getEnum ( ) |
847- result = TEnum ( enum ) and
848- path .isEmpty ( )
849- or
850- result = TTypeParamTypeParameter ( enum .getGenericParamList ( ) .getATypeParam ( ) ) and
851- path = TypePath:: singleton ( result )
852- )
853- }
854- }
855-
856- private import codeql.rust.elements.internal.OperationImpl as OperationImpl
857-
858799 additional class FunctionDecl extends Declaration , Function {
859800 override TypeParameter getTypeParameter ( TypeParameterPosition ppos ) {
860801 typeParamMatchPosition ( this .getGenericParamList ( ) .getATypeParam ( ) , result , ppos )
@@ -872,37 +813,11 @@ private module MethodCallExprMatchingInput implements MatchingWithStateInputSig
872813 this = result .( ImplTraitTypeTypeParameter ) .getFunction ( )
873814 }
874815
875- pragma [ nomagic]
876- private predicate borrowsAt ( int pos ) {
877- exists ( TraitItemNode t , Function f , string path , string method |
878- (
879- f = this
880- or
881- this .implements ( f )
882- ) and
883- f = t .getAssocItem ( method ) and
884- path = t .getCanonicalPath ( _)
885- |
886- // pos.isSelf() and borrows >= 1
887- // or
888- exists ( int borrows |
889- OperationImpl:: isOverloaded ( _, _, path , method , borrows ) and
890- pos = 0 and
891- borrows >= 2
892- )
893- // or
894- // path= "core::ops::index::Index" and
895- // method = "index" and
896- // pos =
897- )
898- }
899-
900816 override Type getParameterType ( DeclarationPosition dpos , TypePath path ) {
901- exists ( Param p , int i , TypePath path0 |
817+ exists ( Param p , int i |
902818 paramPos ( this .getParamList ( ) , p , i ) and
903819 i = dpos .asPosition ( ) and
904- result = p .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path0 ) and
905- if this .borrowsAt ( i ) then path0 .isCons ( TRefTypeParameter ( ) , path ) else path0 = path
820+ result = p .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path )
906821 )
907822 or
908823 dpos .isSelf ( ) and
@@ -911,8 +826,6 @@ private module MethodCallExprMatchingInput implements MatchingWithStateInputSig
911826 result = getSelfParamTypeMention ( self ) .resolveTypeAt ( path )
912827 )
913828 or
914- // or
915- // todo: add special case for operations with implicit borrows
916829 //
917830 // For associated functions, we may also need to match type arguments against
918831 // the `Self` type. For example, in
@@ -939,25 +852,6 @@ private module MethodCallExprMatchingInput implements MatchingWithStateInputSig
939852 )
940853 }
941854
942- pragma [ nomagic]
943- private predicate derefsReturn ( ) {
944- exists ( TraitItemNode t , Function f , string path , string method |
945- (
946- f = this
947- or
948- this .implements ( f )
949- ) and
950- f = t .getAssocItem ( method ) and
951- path = t .getCanonicalPath ( _)
952- |
953- path = "core::ops::index::Index" and
954- method = "index"
955- or
956- path = "core::ops::deref::Deref" and
957- method = "deref"
958- )
959- }
960-
961855 private Type resolveRetType ( TypePath path ) {
962856 result = this .getRetType ( ) .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path )
963857 }
@@ -973,10 +867,6 @@ private module MethodCallExprMatchingInput implements MatchingWithStateInputSig
973867 path = TypePath:: cons ( getFutureOutputTypeParameter ( ) , suffix )
974868 )
975869 else result = this .resolveRetType ( path )
976- // exists(TypePath path0 |
977- // result = this.resolveRetType(path0) and
978- // if this.derefsReturn() then path0.isCons(TRefTypeParameter(), path) else path0 = path
979- // )
980870 }
981871 }
982872
@@ -1005,13 +895,8 @@ private module MethodCallExprMatchingInput implements MatchingWithStateInputSig
1005895 final class Access extends MethodCallExpr {
1006896 pragma [ nomagic]
1007897 Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
1008- exists ( TypeMention arg | result = arg .resolveTypeAt ( path ) |
1009- // exists(Path p, int i |
1010- // p = CallExprImpl::getFunctionPath(this) and
1011- // arg = p.getSegment().getGenericArgList().getTypeArg(pragma[only_bind_into](i)) and
1012- // apos.asTypeParam() = resolvePath(p).getTypeParam(pragma[only_bind_into](i))
1013- // )
1014- // or
898+ exists ( TypeMention arg |
899+ result = arg .resolveTypeAt ( path ) and
1015900 arg = this .getGenericArgList ( ) .getTypeArg ( apos .asMethodTypeArgumentPosition ( ) )
1016901 )
1017902 }
@@ -1467,37 +1352,11 @@ private module CallExprMatchingInput implements MatchingInputSig {
14671352 this = result .( ImplTraitTypeTypeParameter ) .getFunction ( )
14681353 }
14691354
1470- pragma [ nomagic]
1471- private predicate borrowsAt ( int pos ) {
1472- exists ( TraitItemNode t , Function f , string path , string method |
1473- (
1474- f = this
1475- or
1476- this .implements ( f )
1477- ) and
1478- f = t .getAssocItem ( method ) and
1479- path = t .getCanonicalPath ( _)
1480- |
1481- // pos.isSelf() and borrows >= 1
1482- // or
1483- exists ( int borrows |
1484- OperationImpl:: isOverloaded ( _, _, path , method , borrows ) and
1485- pos = 0 and
1486- borrows >= 2
1487- )
1488- // or
1489- // path= "core::ops::index::Index" and
1490- // method = "index" and
1491- // pos =
1492- )
1493- }
1494-
14951355 override Type getParameterType ( DeclarationPosition dpos , TypePath path ) {
1496- exists ( Param p , int i , TypePath path0 |
1356+ exists ( Param p , int i |
14971357 paramPos ( this .getParamList ( ) , p , i ) and
14981358 i = dpos .asPosition ( ) and
1499- result = p .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path0 ) and
1500- if this .borrowsAt ( i ) then path0 .isCons ( TRefTypeParameter ( ) , path ) else path0 = path
1359+ result = p .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path )
15011360 )
15021361 or
15031362 dpos .isSelf ( ) and
@@ -1534,25 +1393,6 @@ private module CallExprMatchingInput implements MatchingInputSig {
15341393 )
15351394 }
15361395
1537- pragma [ nomagic]
1538- private predicate derefsReturn ( ) {
1539- exists ( TraitItemNode t , Function f , string path , string method |
1540- (
1541- f = this
1542- or
1543- this .implements ( f )
1544- ) and
1545- f = t .getAssocItem ( method ) and
1546- path = t .getCanonicalPath ( _)
1547- |
1548- path = "core::ops::index::Index" and
1549- method = "index"
1550- or
1551- path = "core::ops::deref::Deref" and
1552- method = "deref"
1553- )
1554- }
1555-
15561396 private Type resolveRetType ( TypePath path ) {
15571397 result = this .getRetType ( ) .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path )
15581398 }
@@ -1568,10 +1408,6 @@ private module CallExprMatchingInput implements MatchingInputSig {
15681408 path = TypePath:: cons ( getFutureOutputTypeParameter ( ) , suffix )
15691409 )
15701410 else result = this .resolveRetType ( path )
1571- // exists(TypePath path0 |
1572- // result = this.resolveRetType(path0) and
1573- // if this.derefsReturn() then path0.isCons(TRefTypeParameter(), path) else path0 = path
1574- // )
15751411 }
15761412 }
15771413
@@ -2297,9 +2133,9 @@ private Type inferStructPatType(AstNode n, TypePath path) {
22972133 * like `let Some(x) = ...`.
22982134 */
22992135private module TupleStructPatMatchingInput implements MatchingInputSig {
2300- class DeclarationPosition = MethodCallExprMatchingInput :: DeclarationPosition ;
2136+ class DeclarationPosition = CallExprMatchingInput :: DeclarationPosition ;
23012137
2302- class Declaration = MethodCallExprMatchingInput :: TupleDeclaration ;
2138+ class Declaration = CallExprMatchingInput :: TupleDeclaration ;
23032139
23042140 class AccessPosition = DeclarationPosition ;
23052141
@@ -3612,7 +3448,7 @@ private module Debug {
36123448 // filepath.matches("%/crates/wdk-macros/src/lib.rs") and
36133449 // endline = [255 .. 256]
36143450 filepath .matches ( "%/main.rs" ) and
3615- startline = 1846
3451+ startline = 120
36163452 )
36173453 }
36183454
0 commit comments