@@ -1286,6 +1286,18 @@ private module MethodResolution {
12861286
12871287 private Type getReceiverTypeAt ( TypePath path ) {
12881288 result = this .getArgumentTypeAt ( any ( ArgumentPosition pos | pos .isSelf ( ) ) , path )
1289+ or
1290+ exists ( Function f , SelfParam self , TypePath prefix , TypePath suffix |
1291+ f = CallExprImpl:: getResolvedFunction ( this ) and
1292+ self = f .getSelfParam ( ) and
1293+ result = getCallExprTypeQualifier ( this , suffix ) and
1294+ path = prefix .append ( suffix )
1295+ |
1296+ prefix = getSelfParamSelfPath ( self )
1297+ or
1298+ not self .hasTypeRepr ( ) and
1299+ if self .isRef ( ) then prefix = TypePath:: singleton ( TRefTypeParameter ( ) ) else prefix .isEmpty ( )
1300+ )
12891301 }
12901302
12911303 /**
@@ -1557,20 +1569,6 @@ private module MethodResolution {
15571569 forall ( ItemNode i | i = CallExprImpl:: getResolvedFunction ( this ) | i instanceof Method )
15581570 }
15591571
1560- /**
1561- * Holds if this call has a type qualifier, and we are able to resolve,
1562- * using path resolution, the method to a member of `impl`.
1563- *
1564- * When this is the case, we still want to check that the type qualifier
1565- * is an instance of the type being implemented, which is done in
1566- * `TypeQualifierIsInstantiationOfImplSelfInput`.
1567- */
1568- pragma [ nomagic]
1569- predicate hasTypeQualifiedCandidate ( ImplItemNode impl ) {
1570- exists ( getCallExprTypeQualifier ( this , _) ) and
1571- CallExprImpl:: getResolvedFunction ( this ) = impl .getASuccessor ( _)
1572- }
1573-
15741572 pragma [ nomagic]
15751573 override predicate hasNameAndArity ( string name , int arity ) {
15761574 name = CallExprImpl:: getFunctionPath ( this ) .getText ( ) and
@@ -1584,11 +1582,6 @@ private module MethodResolution {
15841582 result = this .getArgList ( ) .getArg ( pos .asPosition ( ) + 1 )
15851583 }
15861584
1587- // needed for `TypeQualifierIsInstantiationOfImplSelfInput`
1588- Type getTypeAt ( TypePath path ) {
1589- result = substituteLookupTraits ( getCallExprTypeQualifier ( this , path ) )
1590- }
1591-
15921585 override predicate supportsAutoDerefAndBorrow ( ) { none ( ) }
15931586 }
15941587
@@ -1699,18 +1692,9 @@ private module MethodResolution {
16991692 )
17001693 }
17011694
1702- pragma [ nomagic]
1703- private predicate typeQualifierIsInstantiationOf ( ImplOrTraitItemNode i ) {
1704- TypeQualifierIsInstantiationOfImplSelf:: isInstantiationOf ( mc_ , i , _)
1705- }
1706-
17071695 pragma [ nomagic]
17081696 private predicate argIsInstantiationOf ( ImplOrTraitItemNode i , string name , int arity ) {
1709- (
1710- ReceiverIsInstantiationOfSelfParam:: argIsInstantiationOf ( this , i , _)
1711- or
1712- this .typeQualifierIsInstantiationOf ( i )
1713- ) and
1697+ ReceiverIsInstantiationOfSelfParam:: argIsInstantiationOf ( this , i , _) and
17141698 mc_ .hasNameAndArity ( name , arity )
17151699 }
17161700
@@ -1833,6 +1817,7 @@ private module MethodResolution {
18331817 MethodCallCand mcc , ImplItemNode impl , TraitItemNode trait , AssocFunctionType selfType ,
18341818 MethodCall mc , Method m , string name , int arity , TypePath strippedTypePath , Type strippedType
18351819 ) {
1820+ // mc = Debug::getRelevantLocatable() and
18361821 potentialInstantiationOf0 ( mcc , impl , selfType , mc , m , name , arity , strippedTypePath ,
18371822 strippedType ) and
18381823 m = trait .getAnAssocItem ( )
@@ -1846,6 +1831,7 @@ private module MethodResolution {
18461831 MethodCall mc , Method m , string name , int arity , TypePath strippedTypePath ,
18471832 Type strippedType
18481833 |
1834+ // mc = Debug::getRelevantLocatable() and
18491835 potentialInstantiationOf0 ( mcc , i , selfType , mc , m , name , arity , strippedTypePath ,
18501836 strippedType ) and
18511837 not (
@@ -1916,45 +1902,6 @@ private module MethodResolution {
19161902 private module ReceiverIsNotInstantiationOfBlanketLikeSelfParam =
19171903 ArgIsInstantiationOf< MethodCallCand , ReceiverIsNotInstantiationOfBlanketLikeSelfParamInput > ;
19181904
1919- /**
1920- * A configuration for matching the type qualifier of a method call
1921- * against the type being implemented in an `impl` block. For example,
1922- * in `Foo::<Bar>::m(x)`, we check that the type `Foo<Bar>` is an
1923- * instance of the type being implemented.
1924- */
1925- private module TypeQualifierIsInstantiationOfImplSelfInput implements
1926- IsInstantiationOfInputSig< MethodCallCallExpr , TypeMentionTypeTree >
1927- {
1928- pragma [ nomagic]
1929- private predicate potentialInstantiationOf0 (
1930- MethodCallCallExpr ce , ImplItemNode impl , TypeMentionTypeTree constraint
1931- ) {
1932- ce .hasTypeQualifiedCandidate ( impl ) and
1933- constraint = impl .getSelfPath ( )
1934- }
1935-
1936- pragma [ nomagic]
1937- predicate potentialInstantiationOf (
1938- MethodCallCallExpr ce , TypeAbstraction abs , TypeMentionTypeTree constraint
1939- ) {
1940- potentialInstantiationOf0 ( ce , abs , constraint ) and
1941- if abs .( Impl ) .hasTrait ( )
1942- then
1943- // inherent methods take precedence over trait methods, so only allow
1944- // trait methods when there are no matching inherent methods
1945- MkMethodCallCand ( ce , _, _) .( MethodCallCand ) .hasNoInherentTarget ( )
1946- else any ( )
1947- }
1948-
1949- predicate relevantConstraint ( TypeMentionTypeTree constraint ) {
1950- potentialInstantiationOf0 ( _, _, constraint )
1951- }
1952- }
1953-
1954- private module TypeQualifierIsInstantiationOfImplSelf =
1955- IsInstantiationOf< MethodCallCallExpr , TypeMentionTypeTree ,
1956- TypeQualifierIsInstantiationOfImplSelfInput > ;
1957-
19581905 /**
19591906 * A configuration for matching the types of positional arguments against the
19601907 * types of parameters, when needed to disambiguate the call.
@@ -3494,8 +3441,8 @@ private module Debug {
34943441 Locatable getRelevantLocatable ( ) {
34953442 exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
34963443 result .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
3497- filepath .matches ( "%/sqlx .rs" ) and
3498- startline = [ 56 .. 60 ]
3444+ filepath .matches ( "%/main .rs" ) and
3445+ startline = 590
34993446 )
35003447 }
35013448
0 commit comments