@@ -1658,14 +1658,14 @@ private module AssocFunctionResolution {
16581658 Type root
16591659 ) {
16601660 exists ( TypePath path |
1661- ArgIsInstantiationOfSelfParam:: argIsNotInstantiationOf ( MkAssocFunctionCallCand ( this ,
1662- selfPos , _ , derefChain , borrow ) , i , _ , path ) and
1661+ ArgIsInstantiationOfSelfParam:: argIsNotInstantiationOf ( this , i , selfPos , derefChain , borrow ,
1662+ path ) and
16631663 path .isCons ( root .getATypeParameter ( ) , _)
16641664 )
16651665 or
16661666 exists ( AssocFunctionType selfType |
1667- ArgIsInstantiationOfSelfParam:: argIsInstantiationOf ( MkAssocFunctionCallCand ( this , selfPos ,
1668- _ , derefChain , borrow ) , i , selfType ) and
1667+ ArgIsInstantiationOfSelfParam:: argIsInstantiationOf ( this , i , selfPos , derefChain , borrow ,
1668+ selfType ) and
16691669 CallArgsAreInstantiationsOf:: argsAreNotInstantiationsOf ( this , i , _) and
16701670 root = selfType .getTypeAt ( TypePath:: nil ( ) )
16711671 )
@@ -2176,8 +2176,17 @@ private module AssocFunctionResolution {
21762176 AssocFunctionCall afc , FunctionPosition selfPos , FunctionPosition selfPosAdj ,
21772177 DerefChain derefChain , BorrowKind borrow
21782178 ) {
2179- // todo: restrict to relevant positions
2180- exists ( afc .getTypeAt ( selfPos , derefChain , borrow , _) ) and
2179+ exists ( TypePath strippedTypePath , Type strippedType |
2180+ strippedType =
2181+ substituteLookupTraits ( afc .getANonPseudoTypeAt ( selfPos , derefChain , borrow ,
2182+ strippedTypePath ) )
2183+ |
2184+ selfPos .isSelfOrTypeQualifier ( )
2185+ or
2186+ blanketLikeCandidate ( afc , _, _, selfPosAdj , _, _, _, _)
2187+ or
2188+ nonBlanketCandidate ( afc , _, _, selfPosAdj , _, _, strippedTypePath , strippedType )
2189+ ) and
21812190 if afc .hasReceiver ( )
21822191 then selfPosAdj = selfPos .getFunctionCallAdjusted ( )
21832192 else selfPosAdj = selfPos
@@ -2427,8 +2436,26 @@ private module AssocFunctionResolution {
24272436 }
24282437 }
24292438
2430- private module ArgIsInstantiationOfSelfParam =
2431- ArgIsInstantiationOf< AssocFunctionCallCand , ArgIsInstantiationOfSelfParamInput > ;
2439+ private module ArgIsInstantiationOfSelfParam {
2440+ import ArgIsInstantiationOf< AssocFunctionCallCand , ArgIsInstantiationOfSelfParamInput >
2441+
2442+ pragma [ nomagic]
2443+ predicate argIsNotInstantiationOf (
2444+ AssocFunctionCall afc , ImplOrTraitItemNode i , FunctionPosition selfPos , DerefChain derefChain ,
2445+ BorrowKind borrow , TypePath path
2446+ ) {
2447+ argIsNotInstantiationOf ( MkAssocFunctionCallCand ( afc , selfPos , _, derefChain , borrow ) , i , _,
2448+ path )
2449+ }
2450+
2451+ pragma [ nomagic]
2452+ predicate argIsInstantiationOf (
2453+ AssocFunctionCall afc , ImplOrTraitItemNode i , FunctionPosition selfPos , DerefChain derefChain ,
2454+ BorrowKind borrow , AssocFunctionType selfType
2455+ ) {
2456+ argIsInstantiationOf ( MkAssocFunctionCallCand ( afc , selfPos , _, derefChain , borrow ) , i , selfType )
2457+ }
2458+ }
24322459
24332460 /**
24342461 * A configuration for anti-matching the type of an argument against the type of
@@ -2592,35 +2619,36 @@ private module MethodCallMatchingInput implements MatchingWithEnvironmentInputSi
25922619 }
25932620
25942621 pragma [ nomagic]
2595- private Type getInferredSelfType ( AccessPosition apos , string derefChainBorrow , TypePath path ) {
2622+ private Type getInferredSelfType (
2623+ FunctionPosition pos , AccessPosition apos , string derefChainBorrow , TypePath path
2624+ ) {
25962625 exists ( DerefChain derefChain , BorrowKind borrow |
2597- result = this .getTypeAt ( apos , derefChain , borrow , path ) and
2598- derefChainBorrow = encodeDerefChainBorrow ( apos , derefChain , borrow )
2626+ result = this .getTypeAt ( pos , derefChain , borrow , path ) and
2627+ derefChainBorrow = encodeDerefChainBorrow ( pos , derefChain , borrow ) and
2628+ if this .hasReceiver ( ) then apos = pos else pos = apos .getFunctionCallAdjusted ( )
25992629 )
26002630 }
26012631
26022632 pragma [ nomagic]
2603- private Type getInferredNonSelfType ( AccessPosition apos , TypePath path ) {
2633+ private Type getInferredNonSelfType ( FunctionPosition pos , AccessPosition apos , TypePath path ) {
26042634 exists ( DerefChain derefChain , BorrowKind borrow |
2605- result = this .getTypeAt ( apos , derefChain , borrow , path ) and
2635+ result = this .getTypeAt ( pos , derefChain , borrow , path ) and
26062636 derefChain .isEmpty ( ) and
2607- borrow .isNoBorrow ( )
2637+ borrow .isNoBorrow ( ) and
2638+ if this .hasReceiver ( ) then apos = pos else pos = apos .getFunctionCallAdjusted ( )
26082639 )
26092640 }
26102641
26112642 bindingset [ derefChainBorrow]
26122643 Type getInferredType ( string derefChainBorrow , AccessPosition apos , TypePath path ) {
26132644 exists ( FunctionPosition pos |
2614- result = this .getInferredSelfType ( pos , derefChainBorrow , path )
2645+ result = this .getInferredSelfType ( pos , apos , derefChainBorrow , path )
26152646 or
26162647 exists ( FunctionPosition selfPos |
26172648 MethodCallMatchingInput:: decodeDerefChainBorrow ( derefChainBorrow , selfPos , _, _) and
2618- result = this .getInferredNonSelfType ( pos , path ) and
2649+ result = this .getInferredNonSelfType ( pos , apos , path ) and
26192650 pos != selfPos
26202651 )
2621- |
2622- // result = this.getInferredNonSelfType(pos, path)
2623- if this .hasReceiver ( ) then apos = pos else pos = apos .getFunctionCallAdjusted ( )
26242652 )
26252653 }
26262654
0 commit comments