@@ -222,6 +222,33 @@ class NonAliasPathTypeMention extends PathTypeMention {
222222 result = this .getPositionalTypeArgument ( pragma [ only_bind_into ] ( i ) , path ) and
223223 tp = this .resolveRootType ( ) .getPositionalTypeParameter ( pragma [ only_bind_into ] ( i ) )
224224 )
225+ or
226+ // Handle the special syntactic sugar for function traits. The syntactic
227+ // form is detected by the presence of a parenthesized argument list which
228+ // is a mandatory part of the syntax [1].
229+ //
230+ // For now we only support `FnOnce` as we can't support the "inherited"
231+ // associated types of `Fn` and `FnMut` yet.
232+ //
233+ // [1]: https://doc.rust-lang.org/reference/paths.html#grammar-TypePathFn
234+ exists ( FnOnceTrait t , PathSegment s |
235+ t = resolved and
236+ s = this .getSegment ( ) and
237+ s .hasParenthesizedArgList ( )
238+ |
239+ tp = TTypeParamTypeParameter ( t .getTypeParam ( ) ) and
240+ result = s .getParenthesizedArgList ( ) .( TypeMention ) .resolveTypeAt ( path )
241+ or
242+ tp = TAssociatedTypeTypeParameter ( t .getOutputType ( ) ) and
243+ (
244+ result = s .getRetType ( ) .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path )
245+ or
246+ // When the `-> ...` return type is omitted, it defaults to `()`.
247+ not s .hasRetType ( ) and
248+ result instanceof UnitType and
249+ path .isEmpty ( )
250+ )
251+ )
225252 }
226253
227254 pragma [ nomagic]
@@ -256,17 +283,6 @@ class NonAliasPathTypeMention extends PathTypeMention {
256283 result = alias .getTypeRepr ( ) and
257284 tp = TAssociatedTypeTypeParameter ( this .getResolvedAlias ( pragma [ only_bind_into ] ( name ) ) )
258285 )
259- or
260- // Handle the special syntactic sugar for function traits. For now we only
261- // support `FnOnce` as we can't support the "inherited" associated types of
262- // `Fn` and `FnMut` yet.
263- exists ( FnOnceTrait t | t = resolved |
264- tp = TTypeParamTypeParameter ( t .getTypeParam ( ) ) and
265- result = this .getSegment ( ) .getParenthesizedArgList ( )
266- or
267- tp = TAssociatedTypeTypeParameter ( t .getOutputType ( ) ) and
268- result = this .getSegment ( ) .getRetType ( ) .getTypeRepr ( )
269- )
270286 }
271287
272288 pragma [ nomagic]
0 commit comments