@@ -1521,23 +1521,14 @@ private module AssocFunctionResolution {
15211521
15221522 private module AssocFunctionTraitIsVisible = TraitIsVisible< assocFunctionCallTraitCandidate / 2 > ;
15231523
1524- pragma [ nomagic]
1525- predicate callVisibleTraitCandidate ( AssocFunctionCall afc , Trait trait ) {
1526- AssocFunctionTraitIsVisible:: traitIsVisible ( afc , trait )
1527- or
1528- // if the call has a trait qualifier then that trait must be visible
1529- trait = afc .getTrait ( )
1530- }
1524+ predicate callVisibleTraitCandidate = AssocFunctionTraitIsVisible:: traitIsVisible / 2 ;
15311525
15321526 bindingset [ afc, impl]
15331527 pragma [ inline_late]
15341528 private predicate callVisibleImplTraitCandidate ( AssocFunctionCall afc , ImplItemNode impl ) {
15351529 callVisibleTraitCandidate ( afc , impl .resolveTraitTy ( ) )
15361530 }
15371531
1538- pragma [ nomagic]
1539- private predicate implHasNoTrait ( Impl i ) { not i .hasTrait ( ) }
1540-
15411532 /**
15421533 * Holds if call `afc` may target function `f` in `i` with type `selfType` at
15431534 * `selfPos`.
@@ -1560,11 +1551,18 @@ private module AssocFunctionResolution {
15601551 assocFunctionInfoNonBlanketLike ( f , name , arity , selfPos , selfPosAdj , i , selfType ,
15611552 strippedTypePath , strippedType , implType , isMethod )
15621553 |
1563- implHasNoTrait ( i )
1554+ i .( Impl ) .isInherent ( ) and
1555+ not afc .hasTrait ( )
15641556 or
15651557 callVisibleImplTraitCandidate ( afc , i )
15661558 or
15671559 callVisibleTraitCandidate ( afc , i )
1560+ or
1561+ exists ( Trait trait | trait = afc .getTrait ( ) |
1562+ i .( ImplItemNode ) .resolveTraitTy ( ) = trait
1563+ or
1564+ i = trait
1565+ )
15681566 )
15691567 }
15701568
@@ -1588,8 +1586,11 @@ private module AssocFunctionResolution {
15881586 exists ( string name , int arity , boolean isMethod |
15891587 afc .hasNameAndArity ( name , arity , _, isMethod ) and
15901588 assocFunctionSelfInfoBlanketLike ( f , name , arity , selfPos , selfPosAdj , impl , _, self ,
1591- blanketPath , blanketTypeParam , isMethod ) and
1589+ blanketPath , blanketTypeParam , isMethod )
1590+ |
15921591 callVisibleImplTraitCandidate ( afc , impl )
1592+ or
1593+ impl .resolveTraitTy ( ) = afc .getTrait ( )
15931594 )
15941595 }
15951596
@@ -1647,17 +1648,15 @@ private module AssocFunctionResolution {
16471648 */
16481649 pragma [ nomagic]
16491650 private predicate isRelevantSelfPos ( FunctionPosition selfPos ) {
1651+ not this .hasReceiver ( ) and
16501652 exists ( TypePath strippedTypePath , Type strippedType |
1651- strippedType = substituteLookupTraits ( this .getTypeAt ( selfPos , strippedTypePath ) )
1653+ strippedType = substituteLookupTraits ( this .getTypeAt ( selfPos , strippedTypePath ) ) and
1654+ strippedType != TNeverType ( ) and
1655+ strippedType != TUnknownType ( )
16521656 |
1653- selfPos . isSelfOrTypeQualifier ( )
1657+ nonBlanketLikeCandidate ( this , _ , _ , selfPos , _ , _ , strippedTypePath , strippedType )
16541658 or
1655- not this .hasReceiver ( ) and
1656- (
1657- blanketLikeCandidate ( this , _, _, selfPos , _, _, _, _)
1658- or
1659- nonBlanketLikeCandidate ( this , _, _, selfPos , _, _, strippedTypePath , strippedType )
1660- )
1659+ blanketLikeCandidate ( this , _, _, selfPos , _, _, strippedTypePath , _)
16611660 )
16621661 }
16631662
@@ -1668,7 +1667,11 @@ private module AssocFunctionResolution {
16681667 Type getSelfTypeAtNoBorrow ( FunctionPosition selfPos , DerefChain derefChain , TypePath path ) {
16691668 result = this .getTypeAt ( selfPos , path ) and
16701669 derefChain .isEmpty ( ) and
1671- this .isRelevantSelfPos ( selfPos )
1670+ (
1671+ selfPos .isSelfOrTypeQualifier ( )
1672+ or
1673+ this .isRelevantSelfPos ( selfPos )
1674+ )
16721675 or
16731676 exists ( DerefImplItemNode impl , DerefChain suffix |
16741677 result =
@@ -2314,7 +2317,7 @@ private module AssocFunctionResolution {
23142317 forall ( Impl i |
23152318 assocFunctionInfoNonBlanketLike ( _, name , arity , _, selfPosAdj , i , _, strippedTypePath ,
23162319 strippedType , _, _) and
2317- not i . hasTrait ( )
2320+ i . isInherent ( )
23182321 |
23192322 this .hasIncompatibleInherentTarget ( i )
23202323 )
@@ -2548,7 +2551,7 @@ private module AssocFunctionResolution {
25482551 AssocFunctionCallCand afcc , TypeAbstraction abs , AssocFunctionType constraint
25492552 ) {
25502553 ArgIsInstantiationOfSelfParamInput:: potentialInstantiationOf0 ( afcc , abs , constraint ) and
2551- abs = any ( Impl i | not i . hasTrait ( ) ) and
2554+ abs . ( Impl ) . isInherent ( ) and
25522555 // todo: comment
25532556 exists ( FunctionPosition selfPosAdj | afcc = MkAssocFunctionCallCand ( _, _, selfPosAdj , _, _) |
25542557 selfPosAdj .isTypeQualifier ( ) or selfPosAdj .asPosition ( ) = 0
0 commit comments