@@ -72,16 +72,24 @@ module FunctionPositionMatchingInput {
7272}
7373
7474private newtype TAssocFunctionType =
75- /** An associated function `f` that should be specialized for `i` at `pos`. */
76- MkAssocFunctionType ( Function f , ImplOrTraitItemNode i , FunctionPosition pos ) {
77- f = i .getASuccessor ( _) and exists ( pos .getTypeMention ( f ) )
75+ /** An associated function `f` in `parent` should be specialized for `i` at `pos`. */
76+ MkAssocFunctionType (
77+ ImplOrTraitItemNode parent , Function f , ImplOrTraitItemNode i , FunctionPosition pos
78+ ) {
79+ parent .getAnAssocItem ( ) = f and
80+ i .getASuccessor ( _) = f and
81+ // When `f` is not directly in `i`, the `parent` should be satisfiable
82+ // through `i`. This ensures that `parent` is either a supertrait of `i` or
83+ // `i` in an `impl` block implementing `parent`.
84+ ( parent = i or BaseTypes:: rootTypesSatisfaction ( _, TTrait ( parent ) , i , _, _) ) and
85+ exists ( pos .getTypeMention ( f ) )
7886 }
7987
80- bindingset [ condition , constraint, tp]
88+ bindingset [ abs , constraint, tp]
8189private Type getTraitConstraintTypeAt (
82- TypeMention condition , TypeMention constraint , TypeParameter tp , TypePath path
90+ TypeAbstraction abs , TypeMention constraint , TypeParameter tp , TypePath path
8391) {
84- BaseTypes:: conditionSatisfiesConstraintTypeAt ( _ , condition , constraint ,
92+ BaseTypes:: conditionSatisfiesConstraintTypeAt ( abs , _ , constraint ,
8593 TypePath:: singleton ( tp ) .appendInverse ( path ) , result )
8694}
8795
@@ -91,28 +99,19 @@ private Type getTraitConstraintTypeAt(
9199 */
92100pragma [ nomagic]
93101Type getAssocFunctionTypeAt ( Function f , ImplOrTraitItemNode i , FunctionPosition pos , TypePath path ) {
94- exists ( MkAssocFunctionType ( f , i , pos ) ) and
95- (
102+ exists ( ImplOrTraitItemNode parent | exists ( MkAssocFunctionType ( parent , f , i , pos ) ) |
96103 // No specialization needed when the function is directly in the trait or
97104 // impl block or the declared type is not a type parameter
98- ( i . getAnAssocItem ( ) = f or not result instanceof TypeParameter ) and
105+ ( parent = i or not result instanceof TypeParameter ) and
99106 result = pos .getTypeMention ( f ) .resolveTypeAt ( path )
100107 or
101- not i . getAnAssocItem ( ) = f and
102- exists ( TypePath prefix , TypePath suffix , TypeParameter tp |
108+ exists ( TypePath prefix , TypePath suffix , TypeParameter tp , TypeMention constraint |
109+ BaseTypes :: rootTypesSatisfaction ( _ , TTrait ( parent ) , i , _ , constraint ) and
103110 path = prefix .append ( suffix ) and
104- tp = pos .getTypeMention ( f ) .resolveTypeAt ( prefix )
105- |
111+ tp = pos .getTypeMention ( f ) .resolveTypeAt ( prefix ) and
106112 if tp = TSelfTypeParameter ( _)
107113 then result = resolveImplOrTraitType ( i , suffix )
108- else
109- exists ( TraitItemNode trait , TypeMention condition , TypeMention constraint |
110- trait .getAnAssocItem ( ) = f and
111- BaseTypes:: rootTypesSatisfaction ( _, TTrait ( trait ) , _, condition , constraint ) and
112- result = getTraitConstraintTypeAt ( condition , constraint , tp , suffix )
113- |
114- condition = i .( Trait ) or condition = i .( Impl ) .getSelfTy ( )
115- )
114+ else result = getTraitConstraintTypeAt ( i , constraint , tp , suffix )
116115 )
117116 )
118117}
@@ -134,31 +133,33 @@ Type getAssocFunctionTypeAt(Function f, ImplOrTraitItemNode i, FunctionPosition
134133 * fn m3(self); // self3
135134 * }
136135 *
137- * impl T2 for X {
136+ * impl T1 for X {
138137 * fn m1(self) { ... } // self4
138+ * }
139139 *
140+ * impl T2 for X {
140141 * fn m3(self) { ... } // self5
141142 * }
142143 * ```
143144 *
144- * param | `impl` or trait | type
145- * ------- | --------------- | ----
146- * `self1 ` | `trait T1` | `T1`
147- * `self1 ` | `trait T2` | `T2`
148- * `self2 ` | `trait T1` | `T1`
149- * `self2 ` | `trait T2` | `T2`
150- * `self2 ` | `impl T2 for X` | `X`
151- * `self3 ` | `trait T2` | `T2`
152- * `self4 ` | `impl T2 for X` | `X`
153- * `self5 ` | `impl T2 for X` | `X`
145+ * f | `impl` or trait | pos | type
146+ * ---- | --------------- | ------ | ----
147+ * `m1 ` | `trait T1` | `self` | `T1`
148+ * `m1 ` | `trait T2` | `self` | `T2`
149+ * `m2 ` | `trait T1` | `self` | `T1`
150+ * `m2 ` | `trait T2` | `self` | `T2`
151+ * `m2 ` | `impl T1 for X` | `self ` | `X`
152+ * `m3 ` | `trait T2` | `self` | `T2`
153+ * `m4 ` | `impl T2 for X` | `self ` | `X`
154+ * `m5 ` | `impl T2 for X` | `self ` | `X`
154155 */
155156class AssocFunctionType extends MkAssocFunctionType {
156157 /**
157158 * Holds if this function type applies to the function `f` at position `pos`,
158159 * when viewed as a member of the `impl` or trait item `i`.
159160 */
160161 predicate appliesTo ( Function f , ImplOrTraitItemNode i , FunctionPosition pos ) {
161- this = MkAssocFunctionType ( f , i , pos )
162+ this = MkAssocFunctionType ( _ , f , i , pos )
162163 }
163164
164165 /**
0 commit comments