@@ -82,7 +82,9 @@ private newtype TAssocFunctionType =
8282 // through `i`. This ensures that `parent` is either a supertrait of `i` or
8383 // `i` in an `impl` block implementing `parent`.
8484 ( parent = i or BaseTypes:: rootTypesSatisfaction ( _, TTrait ( parent ) , i , _, _) ) and
85- exists ( pos .getTypeMention ( f ) )
85+ // We always include the `self` position, even for non-methods, where it is used
86+ // to match type qualifiers against the `impl` or trait type, such as in `Vec::new`.
87+ ( exists ( pos .getTypeMention ( f ) ) or pos .isSelf ( ) )
8688 }
8789
8890bindingset [ abs, constraint, tp]
@@ -116,6 +118,22 @@ Type getAssocFunctionTypeAt(Function f, ImplOrTraitItemNode i, FunctionPosition
116118 )
117119}
118120
121+ /**
122+ * Same as `getAssocFunctionTypeAt`, but also includes types at the `self` position
123+ * for non-methods.
124+ */
125+ pragma [ nomagic]
126+ Type getAssocFunctionTypeInclNonMethodSelfAt (
127+ Function f , ImplOrTraitItemNode i , FunctionPosition pos , TypePath path
128+ ) {
129+ result = getAssocFunctionTypeAt ( f , i , pos , path )
130+ or
131+ f = i .getASuccessor ( _) and
132+ not f .hasSelfParam ( ) and
133+ pos .isSelf ( ) and
134+ result = resolveImplOrTraitType ( i , path )
135+ }
136+
119137/**
120138 * The type of an associated function at a given position, when its implicit
121139 * `Self` type parameter is specialized to a given trait or `impl` block.
@@ -174,7 +192,7 @@ class AssocFunctionType extends MkAssocFunctionType {
174192 Type getTypeAt ( TypePath path ) {
175193 exists ( Function f , FunctionPosition pos , ImplOrTraitItemNode i , Type t |
176194 this .appliesTo ( f , i , pos ) and
177- t = getAssocFunctionTypeAt ( f , i , pos , path )
195+ t = getAssocFunctionTypeInclNonMethodSelfAt ( f , i , pos , path )
178196 |
179197 not t instanceof SelfTypeParameter and
180198 result = t
@@ -184,9 +202,12 @@ class AssocFunctionType extends MkAssocFunctionType {
184202 }
185203
186204 private TypeMention getTypeMention ( ) {
187- exists ( Function f , FunctionPosition pos |
188- this .appliesTo ( f , _, pos ) and
205+ exists ( Function f , ImplOrTraitItemNode i , FunctionPosition pos | this .appliesTo ( f , i , pos ) |
189206 result = pos .getTypeMention ( f )
207+ or
208+ pos .isSelf ( ) and
209+ not f .hasSelfParam ( ) and
210+ result = [ i .( Impl ) .getSelfTy ( ) .( TypeMention ) , i .( TypeMention ) ]
190211 )
191212 }
192213
@@ -294,8 +315,9 @@ module ArgIsInstantiationOf<
294315 */
295316signature module ArgsAreInstantiationsOfInputSig {
296317 /**
297- * Holds if `f` implements a trait function with type parameter `traitTp`, where
298- * we need to check that the type of `f` for `traitTp` is satisfied.
318+ * Holds if `f` implements (or is itself) a trait function with type parameter
319+ * `traitTp`, where we need to check that the type of `f` for `traitTp` is
320+ * satisfied.
299321 *
300322 * `pos` is one of the positions in `f` in which the relevant type occours.
301323 */
0 commit comments