@@ -7,6 +7,12 @@ private import Type
77private import TypeAbstraction
88private import TypeInference
99
10+ bindingset [ trait, name]
11+ pragma [ inline_late]
12+ private TypeAlias getTraitAssocType ( TraitItemNode trait , string name ) {
13+ result = trait .getAssocItem ( name )
14+ }
15+
1016private signature Type getAdditionalPathTypeAtSig ( Path p , TypePath typePath ) ;
1117
1218/**
@@ -286,11 +292,6 @@ private module MkTypeMention<getAdditionalPathTypeAtSig/2 getAdditionalPathTypeA
286292 )
287293 }
288294
289- bindingset [ name]
290- private TypeAlias getResolvedAlias ( string name ) {
291- result = resolved .( TraitItemNode ) .getAssocItem ( name )
292- }
293-
294295 bindingset [ name]
295296 private TypeAlias getResolvedTraitAssocType ( string name ) {
296297 result = resolved .( TraitItemNode ) .getASuccessor ( name )
@@ -322,7 +323,7 @@ private module MkTypeMention<getAdditionalPathTypeAtSig/2 getAdditionalPathTypeA
322323 this = impl .getTraitPath ( ) and
323324 alias = impl .getASuccessor ( name ) and
324325 result = alias .getTypeRepr ( ) and
325- tp = TAssociatedTypeTypeParameter ( resolved , this . getResolvedAlias ( name ) )
326+ tp = TAssociatedTypeTypeParameter ( resolved , getTraitAssocType ( resolved , name ) )
326327 )
327328 }
328329
@@ -651,18 +652,20 @@ class PreTypeMention = PreTypeMention::TypeMention;
651652 * Holds if `path` accesses an associated type `alias` from `trait` on a
652653 * concrete type given by `tm`.
653654 */
654- predicate pathConcreteTypeAssocType ( Path path , PreTypeMention tm , Trait trait , TypeAlias alias ) {
655+ private predicate pathConcreteTypeAssocType (
656+ Path path , PreTypeMention tm , Trait trait , TypeAlias alias
657+ ) {
655658 exists ( Path qualifier |
656659 qualifier = path .getQualifier ( ) and
657660 not resolvePath ( tm .( PathTypeRepr ) .getPath ( ) ) instanceof TypeParam
658661 |
659662 // path of the form `<Type as Trait>::AssocType`
660663 // ^^^ tm ^^^^^^^^^ name
661664 exists ( string name |
662- name = path .getSegment ( ) .getIdentifier ( ) .getText ( ) and
663- tm = qualifier .getSegment ( ) .getTypeRepr ( ) and
665+ name = path .getText ( ) and
664666 trait = resolvePath ( qualifier .getSegment ( ) .getTraitTypeRepr ( ) .getPath ( ) ) and
665- trait .( TraitItemNode ) .getAssocItem ( name ) = alias
667+ getTraitAssocType ( trait , name ) = alias and
668+ tm = qualifier .getSegment ( ) .getTypeRepr ( )
666669 )
667670 or
668671 // path of the form `Self::AssocType` within an `impl` block
@@ -676,21 +679,22 @@ predicate pathConcreteTypeAssocType(Path path, PreTypeMention tm, Trait trait, T
676679 )
677680}
678681
679- private module PathSatisfiesConstraint implements SatisfiesConstraintInputSig< PreTypeMention > {
682+ private module PathSatisfiesConstraintInput implements SatisfiesConstraintInputSig< PreTypeMention > {
680683 predicate relevantConstraint ( PreTypeMention tm , Type constraint ) {
681684 pathConcreteTypeAssocType ( _, tm , constraint .( TraitType ) .getTrait ( ) , _)
682685 }
683686}
684687
688+ module PathSatisfiesConstraint = SatisfiesConstraint< PreTypeMention , PathSatisfiesConstraintInput > ;
689+
685690/**
686691 * Gets the type of `path` at `typePath` when `path` accesses an associated type
687692 * on a concrete type.
688693 */
689694private Type getPathConcreteAssocTypeAt ( Path path , TypePath typePath ) {
690695 exists ( PreTypeMention tm , TraitItemNode t , TypeAlias alias , TypePath path0 |
691696 pathConcreteTypeAssocType ( path , tm , t , alias ) and
692- SatisfiesConstraint< PreTypeMention , PathSatisfiesConstraint > :: satisfiesConstraintType ( tm ,
693- TTrait ( t ) , path0 , result ) and
697+ PathSatisfiesConstraint:: satisfiesConstraintType ( tm , TTrait ( t ) , path0 , result ) and
694698 path0 .isCons ( TAssociatedTypeTypeParameter ( t , alias ) , typePath )
695699 )
696700}
0 commit comments