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