@@ -981,93 +981,32 @@ private AssociatedTypeTypeParameter getFutureOutputTypeParameter() {
981
981
result .getTypeAlias ( ) = any ( FutureTrait ft ) .getOutputType ( )
982
982
}
983
983
984
- /**
985
- * A matching configuration for resolving types of `.await` expressions.
986
- */
987
- private module AwaitExprMatchingInput implements MatchingInputSig {
988
- private newtype TDeclarationPosition =
989
- TSelfDeclarationPosition ( ) or
990
- TOutputPos ( )
991
-
992
- class DeclarationPosition extends TDeclarationPosition {
993
- predicate isSelf ( ) { this = TSelfDeclarationPosition ( ) }
994
-
995
- predicate isOutput ( ) { this = TOutputPos ( ) }
996
-
997
- string toString ( ) {
998
- this .isSelf ( ) and
999
- result = "self"
1000
- or
1001
- this .isOutput ( ) and
1002
- result = "(output)"
1003
- }
1004
- }
1005
-
1006
- private class BuiltinsAwaitFile extends File {
1007
- BuiltinsAwaitFile ( ) {
1008
- this .getBaseName ( ) = "await.rs" and
1009
- this .getParentContainer ( ) instanceof Builtins:: BuiltinsFolder
1010
- }
1011
- }
1012
-
1013
- class Declaration extends Function {
1014
- Declaration ( ) {
1015
- this .getFile ( ) instanceof BuiltinsAwaitFile and
1016
- this .getName ( ) .getText ( ) = "await_type_matching"
1017
- }
1018
-
1019
- TypeParameter getTypeParameter ( TypeParameterPosition ppos ) {
1020
- typeParamMatchPosition ( this .getGenericParamList ( ) .getATypeParam ( ) , result , ppos )
1021
- }
1022
-
1023
- Type getDeclaredType ( DeclarationPosition dpos , TypePath path ) {
1024
- dpos .isSelf ( ) and
1025
- result = this .getParam ( 0 ) .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path )
1026
- or
1027
- dpos .isOutput ( ) and
1028
- result = this .getRetType ( ) .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path )
1029
- }
1030
- }
1031
-
1032
- class AccessPosition = DeclarationPosition ;
1033
-
1034
- class Access extends AwaitExpr {
1035
- Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) { none ( ) }
1036
-
1037
- AstNode getNodeAt ( AccessPosition apos ) {
1038
- result = this .getExpr ( ) and
1039
- apos .isSelf ( )
1040
- or
1041
- result = this and
1042
- apos .isOutput ( )
1043
- }
1044
-
1045
- Type getInferredType ( AccessPosition apos , TypePath path ) {
1046
- result = inferType ( this .getNodeAt ( apos ) , path )
1047
- }
1048
-
1049
- Declaration getTarget ( ) { exists ( this ) and exists ( result ) }
1050
- }
1051
-
1052
- predicate accessDeclarationPositionMatch ( AccessPosition apos , DeclarationPosition dpos ) {
1053
- apos = dpos
1054
- }
1055
- }
1056
-
1057
984
pragma [ nomagic]
1058
985
private TraitType inferAsyncBlockExprRootType ( AsyncBlockExpr abe ) {
1059
986
// `typeEquality` handles the non-root case
1060
987
exists ( abe ) and
1061
988
result = getFutureTraitType ( )
1062
989
}
1063
990
1064
- private module AwaitExprMatching = Matching< AwaitExprMatchingInput > ;
991
+ final class AwaitTarget extends Expr {
992
+ AwaitTarget ( ) { this = any ( AwaitExpr ae ) .getExpr ( ) }
993
+
994
+ Type getTypeAt ( TypePath path ) { result = inferType ( this , path ) }
995
+ }
996
+
997
+ private module AwaitSatisfiesConstraintInput implements SatisfiesConstraintSig< AwaitTarget > {
998
+ predicate relevantConstraint ( AwaitTarget term , Type constraint ) {
999
+ exists ( term ) and
1000
+ constraint .( TraitType ) .getTrait ( ) instanceof FutureTrait
1001
+ }
1002
+ }
1065
1003
1066
1004
pragma [ nomagic]
1067
1005
private Type inferAwaitExprType ( AstNode n , TypePath path ) {
1068
- exists ( AwaitExprMatchingInput:: Access a , AwaitExprMatchingInput:: AccessPosition apos |
1069
- n = a .getNodeAt ( apos ) and
1070
- result = AwaitExprMatching:: inferAccessType ( a , apos , path )
1006
+ exists ( TypePath exprPath |
1007
+ SatisfiesConstraint< AwaitTarget , AwaitSatisfiesConstraintInput > :: satisfiesConstraintTypeMention ( n .( AwaitExpr )
1008
+ .getExpr ( ) , _, exprPath , result ) and
1009
+ exprPath .isCons ( getFutureOutputTypeParameter ( ) , path )
1071
1010
)
1072
1011
or
1073
1012
// This case is needed for `async` functions and blocks, where we assign
0 commit comments