@@ -1331,9 +1331,7 @@ private module MethodResolution {
13311331 * parameter type, or because the blanket constraint is not satisfied.
13321332 */
13331333 pragma [ nomagic]
1334- private predicate hasIncompatibleBlanketLikeTarget (
1335- ImplItemNode impl , string derefChain , boolean borrow
1336- ) {
1334+ predicate hasIncompatibleBlanketLikeTarget ( ImplItemNode impl , string derefChain , boolean borrow ) {
13371335 ReceiverIsNotInstantiationOfBlanketLikeSelfParam:: argIsNotInstantiationOf ( MkMethodCallCand ( this ,
13381336 derefChain , borrow ) , impl , _)
13391337 or
@@ -1675,8 +1673,13 @@ private module MethodResolution {
16751673 * ruled out as a candidate for this call.
16761674 */
16771675 pragma [ nomagic]
1678- private predicate hasIncompatibleInherentTarget ( Impl impl ) {
1679- ReceiverIsNotInstantiationOfInherentSelfParam:: argIsNotInstantiationOf ( this , impl , _)
1676+ predicate hasIncompatibleImplTarget ( Impl impl ) {
1677+ ReceiverIsInstantiationOfSelfParam:: argIsNotInstantiationOf ( this , impl , _)
1678+ }
1679+
1680+ pragma [ nomagic]
1681+ predicate hasIncompatibleBlanketLikeTarget ( ImplItemNode impl ) {
1682+ mc_ .hasIncompatibleBlanketLikeTarget ( impl , derefChain , borrow )
16801683 }
16811684
16821685 /**
@@ -1691,7 +1694,7 @@ private module MethodResolution {
16911694 methodInfoNonBlanket ( _, name , arity , i , _, strippedTypePath , strippedType ) and
16921695 not i .hasTrait ( )
16931696 |
1694- this .hasIncompatibleInherentTarget ( i )
1697+ this .hasIncompatibleImplTarget ( i )
16951698 )
16961699 )
16971700 }
@@ -1771,27 +1774,108 @@ private module MethodResolution {
17711774 IsInstantiationOfInputSig< MethodCallCand , AssocFunctionType >
17721775 {
17731776 pragma [ nomagic]
1774- additional predicate potentialInstantiationOf0 (
1777+ private predicate methodInfoImplTrait (
1778+ Method m , string name , int arity , ImplItemNode impl , TraitItemNode trait ,
1779+ TypePath strippedTypePath , Type strippedType
1780+ ) {
1781+ methodInfo ( m , name , arity , impl , _, strippedTypePath , strippedType ) and
1782+ trait = impl .resolveTraitTy ( )
1783+ }
1784+
1785+ pragma [ nomagic]
1786+ private predicate methodInfoTypeParamImplTrait (
1787+ Method m , string name , int arity , ImplItemNode impl , TraitItemNode trait ,
1788+ TypePath strippedTypePath , TypeParam tp
1789+ ) {
1790+ methodInfoImplTrait ( m , name , arity , impl , trait , strippedTypePath , TTypeParamTypeParameter ( tp ) )
1791+ }
1792+
1793+ pragma [ inline]
1794+ private predicate methodInfoNonBlanketImplTrait (
1795+ string name , int arity , ImplItemNode impl , TraitItemNode trait , TypePath strippedTypePath ,
1796+ Type strippedType
1797+ ) {
1798+ exists ( Method m |
1799+ methodInfoImplTrait ( m , name , arity , impl , trait , strippedTypePath , strippedType ) or
1800+ methodInfoTypeParamImplTrait ( m , name , arity , impl , trait , strippedTypePath , _)
1801+ |
1802+ m = impl .getAnAssocItem ( ) and
1803+ not BlanketImplementation:: isBlanketLike ( impl , _, _)
1804+ )
1805+ }
1806+
1807+ pragma [ nomagic]
1808+ private predicate methodInfoBlanketLikeImplTrait (
1809+ string name , int arity , ImplItemNode impl , Trait trait
1810+ ) {
1811+ exists ( Method m |
1812+ methodInfoBlanketLike ( m , name , arity , impl , trait , _, _, _) and
1813+ m = impl .getAnAssocItem ( )
1814+ )
1815+ }
1816+
1817+ pragma [ nomagic]
1818+ private predicate potentialInstantiationOf0 (
1819+ MethodCallCand mcc , ImplOrTraitItemNode i , AssocFunctionType selfType , MethodCall mc ,
1820+ Method m , string name , int arity , TypePath strippedTypePath , Type strippedType
1821+ ) {
1822+ mcc .hasSignature ( mc , strippedTypePath , strippedType , name , arity ) and
1823+ (
1824+ methodCallNonBlanketCandidate ( mc , m , i , selfType , strippedTypePath , strippedType )
1825+ or
1826+ methodCallBlanketLikeCandidate ( mc , m , i , selfType , _, _) and
1827+ ReceiverSatisfiesBlanketLikeConstraint:: satisfiesBlanketConstraint ( mcc , i )
1828+ )
1829+ }
1830+
1831+ pragma [ nomagic]
1832+ private predicate potentialInstantiationOf1 (
1833+ MethodCallCand mcc , ImplItemNode impl , TraitItemNode trait , AssocFunctionType selfType ,
1834+ MethodCall mc , Method m , string name , int arity , TypePath strippedTypePath , Type strippedType
1835+ ) {
1836+ potentialInstantiationOf0 ( mcc , impl , selfType , mc , m , name , arity , strippedTypePath ,
1837+ strippedType ) and
1838+ m = trait .getAnAssocItem ( )
1839+ }
1840+
1841+ pragma [ nomagic]
1842+ private predicate potentialInstantiationOf1 (
17751843 MethodCallCand mcc , ImplOrTraitItemNode i , AssocFunctionType selfType
17761844 ) {
17771845 exists (
17781846 MethodCall mc , Method m , string name , int arity , TypePath strippedTypePath ,
17791847 Type strippedType
17801848 |
1781- mcc .hasSignature ( mc , strippedTypePath , strippedType , name , arity )
1849+ potentialInstantiationOf0 ( mcc , i , selfType , mc , m , name , arity , strippedTypePath ,
1850+ strippedType ) and
1851+ not (
1852+ i instanceof ImplItemNode and
1853+ m = any ( TraitItemNode trait ) .getAnAssocItem ( )
1854+ )
1855+ )
1856+ or
1857+ exists (
1858+ MethodCall mc , TraitItemNode trait , Method m , string name , int arity ,
1859+ TypePath strippedTypePath , Type strippedType
17821860 |
1783- methodCallNonBlanketCandidate ( mc , m , i , selfType , strippedTypePath , strippedType )
1784- or
1785- methodCallBlanketLikeCandidate ( mc , m , i , selfType , _, _) and
1786- ReceiverSatisfiesBlanketLikeConstraint:: satisfiesBlanketConstraint ( mcc , i )
1861+ potentialInstantiationOf1 ( mcc , i , trait , selfType , mc , m , name , arity , strippedTypePath ,
1862+ strippedType ) and
1863+ forall ( ImplItemNode impl |
1864+ methodInfoNonBlanketImplTrait ( name , arity , impl , trait , strippedTypePath , strippedType )
1865+ |
1866+ mcc .hasIncompatibleImplTarget ( impl )
1867+ ) and
1868+ forall ( ImplItemNode impl | methodInfoBlanketLikeImplTrait ( name , arity , impl , trait ) |
1869+ mcc .hasIncompatibleBlanketLikeTarget ( impl )
1870+ )
17871871 )
17881872 }
17891873
17901874 pragma [ nomagic]
17911875 predicate potentialInstantiationOf (
17921876 MethodCallCand mcc , TypeAbstraction abs , AssocFunctionType constraint
17931877 ) {
1794- potentialInstantiationOf0 ( mcc , abs , constraint ) and
1878+ potentialInstantiationOf1 ( mcc , abs , constraint ) and
17951879 if abs .( Impl ) .hasTrait ( )
17961880 then
17971881 // inherent methods take precedence over trait methods, so only allow
@@ -1871,25 +1955,6 @@ private module MethodResolution {
18711955 IsInstantiationOf< MethodCallCallExpr , TypeMentionTypeTree ,
18721956 TypeQualifierIsInstantiationOfImplSelfInput > ;
18731957
1874- /**
1875- * A configuration for anti-matching the type of a receiver against the type of
1876- * a `self` parameter in an inherent method.
1877- */
1878- private module ReceiverIsNotInstantiationOfInherentSelfParamInput implements
1879- IsInstantiationOfInputSig< MethodCallCand , AssocFunctionType >
1880- {
1881- pragma [ nomagic]
1882- predicate potentialInstantiationOf (
1883- MethodCallCand mcc , TypeAbstraction abs , AssocFunctionType constraint
1884- ) {
1885- ReceiverIsInstantiationOfSelfParamInput:: potentialInstantiationOf0 ( mcc , abs , constraint ) and
1886- abs = any ( Impl i | not i .hasTrait ( ) )
1887- }
1888- }
1889-
1890- private module ReceiverIsNotInstantiationOfInherentSelfParam =
1891- ArgIsInstantiationOf< MethodCallCand , ReceiverIsNotInstantiationOfInherentSelfParamInput > ;
1892-
18931958 /**
18941959 * A configuration for matching the types of positional arguments against the
18951960 * types of parameters, when needed to disambiguate the call.
0 commit comments