@@ -38,6 +38,8 @@ private module Input1 implements InputSig1<Location> {
3838
3939 class Type = T:: Type ;
4040
41+ class PseudoType = T:: PseudoType ;
42+
4143 class UnknownType = T:: UnknownType ;
4244
4345 class TypeParameter = T:: TypeParameter ;
@@ -645,7 +647,7 @@ private module Input3 implements InputSig3 {
645647 not tp = c .getParameterType ( _, _) and
646648 // check that no explicit type arguments have been supplied for `tp`
647649 not exists ( TypeArgumentPosition tapos |
648- this .getTypeArgument ( tapos , _) != TUnknownType ( ) and
650+ this .getTypeArgument ( tapos , _) = any ( Type t | not t instanceof UnknownType ) and
649651 TTypeParamTypeParameter ( tapos .asTypeParam ( ) ) = tp
650652 )
651653 )
@@ -734,10 +736,16 @@ private module Input3 implements InputSig3 {
734736 path2 = TypePath:: singleton ( tt .getPositionalTypeParameter ( i ) )
735737 )
736738 or
737- exists ( ClosureExpr ce , int index |
738- n1 = ce .getParam ( index ) .getPat ( ) and
739- n2 = ce and
739+ exists ( ClosureExpr ce , int index , Param p |
740740 path1 .isEmpty ( ) and
741+ p = ce .getParam ( index )
742+ |
743+ n1 = p .getPat ( ) and
744+ n2 = p and
745+ path2 .isEmpty ( )
746+ or
747+ n1 = p and
748+ n2 = ce and
741749 path2 = closureParameterPath ( ce .getNumberOfParams ( ) , index )
742750 )
743751 }
@@ -881,10 +889,6 @@ private module Input3 implements InputSig3 {
881889 Type inferType ( AstNode n , TypePath path ) {
882890 result = M3:: inferType ( n , path )
883891 or
884- isPanicMacroCall ( n ) and
885- path .isEmpty ( ) and
886- result instanceof UnknownType
887- or
888892 result = inferAssignmentOperationType ( n , path )
889893 or
890894 result = inferTryExprType ( n , path )
@@ -904,6 +908,8 @@ private module Input3 implements InputSig3 {
904908 result = inferDeconstructionPatType ( n , path )
905909 or
906910 result = inferUnknownType ( n , path )
911+ or
912+ result = inferParamPatType ( n , path )
907913 }
908914}
909915
@@ -1318,7 +1324,7 @@ private module ContextualTyping {
13181324 abstract Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) ;
13191325
13201326 predicate hasTypeArgument ( TypeArgumentPosition apos ) {
1321- this .getTypeArgument ( apos , _) != TUnknownType ( )
1327+ this .getTypeArgument ( apos , _) = any ( Type t | not t instanceof UnknownType )
13221328 }
13231329
13241330 /**
@@ -1829,7 +1835,7 @@ private module AssocFunctionResolution {
18291835 not this .hasReceiver ( ) and
18301836 exists ( TypePath strippedTypePath , Type strippedType |
18311837 strippedType = substituteLookupTraits ( this , this .getTypeAt ( selfPos , strippedTypePath ) ) and
1832- strippedType != TUnknownType ( )
1838+ not strippedType instanceof UnknownType
18331839 |
18341840 nonBlanketLikeCandidate ( this , _, selfPos , _, _, strippedTypePath , strippedType )
18351841 or
@@ -1925,7 +1931,7 @@ private module AssocFunctionResolution {
19251931 FunctionPosition selfPos , DerefChain derefChain , BorrowKind borrow , TypePath path
19261932 ) {
19271933 result = this .getSelfTypeAt ( selfPos , derefChain , borrow , path ) and
1928- result != TUnknownType ( )
1934+ not result instanceof UnknownType
19291935 }
19301936
19311937 pragma [ nomagic]
@@ -2584,7 +2590,7 @@ private module AssocFunctionResolution {
25842590
25852591 Type getTypeAt ( TypePath path ) {
25862592 result = substituteLookupTraits ( afc , afc .getSelfTypeAtNoBorrow ( selfPos , derefChain , path ) ) and
2587- result != TUnknownType ( )
2593+ not result instanceof UnknownType
25882594 }
25892595
25902596 string toString ( ) { result = afc + " [" + derefChain .toString ( ) + "]" }
@@ -3144,12 +3150,43 @@ private Type inferUnknownType(AstNode n, TypePath path) {
31443150 or
31453151 n .( Input3:: Construction ) .hasUnknownReturnTypeAt ( path )
31463152 or
3147- exists ( Param p |
3148- not p .hasTypeRepr ( ) and
3149- n = p .getPat ( ) and
3150- path .isEmpty ( )
3153+ // non-`self` parameters without type annotations always belong to closures, so
3154+ // we want
3155+ n = any ( Param p | not p .hasTypeRepr ( ) ) and
3156+ path .isEmpty ( )
3157+ or
3158+ isPanicMacroCall ( n ) and
3159+ path .isEmpty ( )
3160+ )
3161+ }
3162+
3163+ private Type inferParamPatType ( AstNode n , TypePath path ) {
3164+ exists ( ClosureExpr ce , Param p | p = ce .getAParam ( ) |
3165+ n = p .getPat ( ) and
3166+ path .isEmpty ( ) and
3167+ result = TClosureParameterType ( p )
3168+ or
3169+ exists ( TypePath ret | inferType ( ce , ret ) = TClosureParameterType ( p ) |
3170+ n = ce and
3171+ path = ret and
3172+ result = TUnknownType ( )
3173+ or
3174+ inferType ( ce , ret .appendInverse ( path ) ) = result and
3175+ n = p
3176+ )
3177+ or
3178+ exists ( AstNode n0 , TypePath prefix |
3179+ inferType ( n0 , prefix ) = TClosureParameterType ( p ) and
3180+ result = inferTypeCertain ( n0 , prefix .appendInverse ( path ) ) and
3181+ n = p
31513182 )
31523183 )
3184+ or
3185+ n =
3186+ any ( Param p |
3187+ result = inferType ( p , path ) and
3188+ not result instanceof UnknownType
3189+ ) .getPat ( )
31533190}
31543191
31553192pragma [ nomagic]
0 commit comments