@@ -1531,7 +1531,10 @@ private module MethodCallResolution {
15311531 ) {
15321532 exists ( MethodCall mc , string name , int arity |
15331533 mcc .hasSignature ( mc , _, _, name , arity ) and
1534- methodCallBlanketCandidate ( mc , m , _, _, blanketPath , blanketTypeParam )
1534+ methodCallBlanketCandidate ( mc , m , _, _, blanketPath , blanketTypeParam ) and
1535+ // inherent methods take precedence over trait methods, so only allow
1536+ // trait methods when there are no matching inherent methods
1537+ mcc .hasNoInherentTarget ( )
15351538 )
15361539 }
15371540 }
@@ -1544,23 +1547,36 @@ private module MethodCallResolution {
15441547 IsInstantiationOfInputSig< MethodCallCand , FunctionType >
15451548 {
15461549 pragma [ nomagic]
1547- predicate potentialInstantiationOf (
1548- MethodCallCand mcc , TypeAbstraction abs , FunctionType constraint
1550+ additional predicate potentialInstantiationOf0 (
1551+ MethodCallCand mcc , ImplOrTraitItemNode i , FunctionType selfType
15491552 ) {
15501553 exists (
15511554 MethodCall mc , Method m , string name , int arity , TypePath strippedTypePath ,
15521555 Type strippedType
15531556 |
15541557 mcc .hasSignature ( mc , strippedTypePath , strippedType , name , arity )
15551558 |
1556- methodCallNonBlanketCandidate ( mc , m , abs , constraint , strippedTypePath , strippedType )
1559+ methodCallNonBlanketCandidate ( mc , m , i , selfType , strippedTypePath , strippedType )
15571560 or
1558- methodCallBlanketCandidate ( mc , m , abs , constraint , _, _) and
1561+ methodCallBlanketCandidate ( mc , m , i , selfType , _, _) and
15591562 BlanketImplementation:: SatisfiesBlanketConstraint< MethodCallCand , SatisfiesBlanketConstraintInput > :: satisfiesBlanketConstraint ( mcc ,
15601563 m )
15611564 )
15621565 }
15631566
1567+ pragma [ nomagic]
1568+ predicate potentialInstantiationOf (
1569+ MethodCallCand mcc , TypeAbstraction abs , FunctionType constraint
1570+ ) {
1571+ potentialInstantiationOf0 ( mcc , abs , constraint ) and
1572+ if abs .( Impl ) .hasTrait ( )
1573+ then
1574+ // inherent methods take precedence over trait methods, so only allow
1575+ // trait methods when there are no matching inherent methods
1576+ mcc .hasNoInherentTarget ( )
1577+ else any ( )
1578+ }
1579+
15641580 predicate relevantTypeMention ( FunctionType constraint ) {
15651581 methodInfo ( _, _, _, _, constraint , _, _)
15661582 }
@@ -1597,7 +1613,7 @@ private module MethodCallResolution {
15971613 predicate potentialInstantiationOf (
15981614 MethodCallCand mcc , TypeAbstraction abs , FunctionType constraint
15991615 ) {
1600- MethodCallReceiverIsInstantiationOfInput:: potentialInstantiationOf ( mcc , abs , constraint ) and
1616+ MethodCallReceiverIsInstantiationOfInput:: potentialInstantiationOf0 ( mcc , abs , constraint ) and
16011617 abs = any ( Impl i | not i .hasTrait ( ) )
16021618 }
16031619
0 commit comments