@@ -1369,6 +1369,21 @@ private class BorrowKind extends TBorrowKind {
13691369 * [1]: https://doc.rust-lang.org/reference/expressions/method-call-expr.html#r-expr.method.candidate-receivers
13701370 */
13711371private module MethodResolution {
1372+ pragma [ nomagic]
1373+ private predicate functionResolutionDependsOnArgument (
1374+ ImplItemNode impl , Function f , TypeParameter tp , FunctionPosition pos
1375+ ) {
1376+ FunctionOverloading:: functionResolutionDependsOnArgument ( impl , f , tp , pos )
1377+ // or
1378+ // // For inherent implementations of generic types, we also need to check the type being
1379+ // // implemented. We arbitrarily choose the first type parameter of the type being implemented
1380+ // // to represent this case.
1381+ // f = impl.getAnAssocItem() and
1382+ // not impl.(Impl).hasTrait() and
1383+ // tp = TTypeParamTypeParameter(impl.resolveSelfTy().getTypeParam(0)) and
1384+ // pos.isSelf()
1385+ }
1386+
13721387 pragma [ nomagic]
13731388 private predicate traitFunctionResolutionDependsOnArgument0 (
13741389 // todo: copied
@@ -1381,7 +1396,7 @@ private module MethodResolution {
13811396 (
13821397 traitTp = TSelfTypeParameter ( trait )
13831398 or
1384- FunctionOverloading :: functionResolutionDependsOnArgument ( impl , implFunction , traitTp , pos )
1399+ functionResolutionDependsOnArgument ( impl , implFunction , traitTp , pos )
13851400 )
13861401 }
13871402
@@ -1593,7 +1608,8 @@ private module MethodResolution {
15931608 exists ( string name , int arity |
15941609 mc .hasNameAndArity ( name , arity ) and
15951610 assocFunctionInfoNonBlanket ( f , name , arity , selfPos , pos , i , self , strippedTypePath ,
1596- strippedType )
1611+ strippedType ) and
1612+ if mc .hasReceiver ( ) then f instanceof Method else any ( )
15971613 |
15981614 i =
15991615 any ( Impl impl |
@@ -1628,7 +1644,8 @@ private module MethodResolution {
16281644 exists ( string name , int arity |
16291645 mc .hasNameAndArity ( name , arity ) and
16301646 assocFunctionSelfInfoBlanketLike ( f , name , arity , selfPos , pos , impl , _, self , blanketPath ,
1631- blanketTypeParam )
1647+ blanketTypeParam ) and
1648+ if mc .hasReceiver ( ) then f instanceof Method else any ( )
16321649 |
16331650 methodCallVisibleImplTraitCandidate ( mc , impl )
16341651 or
@@ -2201,7 +2218,8 @@ private module MethodResolution {
22012218 exists ( getCallExprPathQualifier ( this ) ) and
22022219 // even if a method cannot be resolved by path resolution, it may still
22032220 // be possible to resolve a blanket implementation (so not `forex`)
2204- forall ( ItemNode i | i = CallExprImpl:: getResolvedFunction ( this ) | i instanceof Function )
2221+ forall ( ItemNode i | i = CallExprImpl:: getResolvedFunction ( this ) | i instanceof Function ) and
2222+ not exists ( this .( NonMethodResolution:: NonMethodCall ) .resolveCallTargetViaPathResolution ( ) )
22052223 }
22062224
22072225 pragma [ nomagic]
@@ -2303,6 +2321,7 @@ private module MethodResolution {
23032321 MethodCall mc , FunctionPosition selfPos , FunctionPosition pos , DerefChain derefChain ,
23042322 BorrowKind borrow
23052323 ) {
2324+ // todo: restrict to relevant positions
23062325 exists ( mc .getACandidateReceiverTypeAt ( selfPos , derefChain , borrow , _) ) and
23072326 if mc .hasReceiver ( )
23082327 then
@@ -2408,7 +2427,7 @@ private module MethodResolution {
24082427 pragma [ nomagic]
24092428 Function resolveCallTarget ( ImplOrTraitItemNode i ) {
24102429 result = this .resolveCallTargetCand ( i ) and
2411- not FunctionOverloading :: functionResolutionDependsOnArgument ( i , result , _, _)
2430+ not functionResolutionDependsOnArgument ( i , result , _, _)
24122431 or
24132432 MethodArgsAreInstantiationsOf:: argsAreInstantiationsOf ( mc_ , i , result )
24142433 }
@@ -2569,11 +2588,22 @@ private module MethodResolution {
25692588 ) {
25702589 mc = Debug:: getRelevantLocatable ( ) and
25712590 mcc .hasSignature ( mc , pos , strippedTypePath , strippedType , name , arity ) and
2572- (
2573- methodCallNonBlanketCandidate ( mc , f , _, pos , i , selfType , strippedTypePath , strippedType )
2574- or
2575- methodCallBlanketLikeCandidate ( mc , f , _, pos , i , selfType , _, _) and
2576- ReceiverSatisfiesBlanketLikeConstraint:: satisfiesBlanketConstraint ( mcc , i )
2591+ // methodCallNonBlanketCandidate(mc, f, _, pos, i, selfType, strippedTypePath, strippedType)
2592+ mc .hasNameAndArity ( name , arity ) and
2593+ exists ( FunctionPosition selfPos |
2594+ assocFunctionInfoNonBlanket ( f , name , arity , selfPos , pos , i , selfType , strippedTypePath ,
2595+ strippedType )
2596+ // |
2597+ // i =
2598+ // any(Impl impl |
2599+ // not impl.hasTrait()
2600+ // or
2601+ // methodCallVisibleImplTraitCandidate(mc, impl)
2602+ // )
2603+ // or
2604+ // methodCallVisibleTraitCandidate(mc, i)
2605+ // or
2606+ // i.(ImplItemNode).resolveTraitTy() = mc.getTrait()
25772607 )
25782608 }
25792609
@@ -2650,7 +2680,7 @@ private module MethodResolution {
26502680 */
26512681 private module MethodArgsAreInstantiationsOfInput implements ArgsAreInstantiationsOfInputSig {
26522682 predicate toCheck ( ImplOrTraitItemNode i , Function f , TypeParameter traitTp , FunctionPosition pos ) {
2653- FunctionOverloading :: functionResolutionDependsOnArgument ( i , f , traitTp , pos )
2683+ functionResolutionDependsOnArgument ( i , f , traitTp , pos )
26542684 }
26552685
26562686 final private class MethodCallFinal = MethodCall ;
@@ -4116,8 +4146,8 @@ private module Debug {
41164146 Locatable getRelevantLocatable ( ) {
41174147 exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
41184148 result .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
4119- filepath .matches ( "%/overloading .rs" ) and
4120- startline = 399
4149+ filepath .matches ( "%/main .rs" ) and
4150+ startline = 93
41214151 )
41224152 }
41234153
0 commit comments