@@ -77,6 +77,16 @@ private module Input1 implements InputSig1<Location> {
7777 apos .asMethodTypeArgumentPosition ( ) = ppos .asTypeParam ( ) .getPosition ( )
7878 }
7979
80+ private int getImplTraitTypeParameterId ( ImplTraitTypeParameter tp ) {
81+ tp =
82+ rank [ result ] ( ImplTraitTypeParameter tp0 , int bounds , int i |
83+ bounds = tp0 .getImplTraitType ( ) .getNumberOfBounds ( ) and
84+ i = tp0 .getIndex ( )
85+ |
86+ tp0 order by bounds , i
87+ )
88+ }
89+
8090 int getTypeParameterId ( TypeParameter tp ) {
8191 tp =
8292 rank [ result ] ( TypeParameter tp0 , int kind , int id |
@@ -90,6 +100,9 @@ private module Input1 implements InputSig1<Location> {
90100 node = tp0 .( AssociatedTypeTypeParameter ) .getTypeAlias ( ) or
91101 node = tp0 .( SelfTypeParameter ) .getTrait ( )
92102 )
103+ or
104+ kind = 2 and
105+ id = getImplTraitTypeParameterId ( tp0 )
93106 |
94107 tp0 order by kind , id
95108 )
@@ -228,7 +241,11 @@ private predicate typeEquality(AstNode n1, TypePath prefix1, AstNode n2, TypePat
228241 or
229242 n1 = n2 .( ParenExpr ) .getExpr ( )
230243 or
231- n1 = n2 .( BlockExpr ) .getStmtList ( ) .getTailExpr ( )
244+ n2 =
245+ any ( BlockExpr be |
246+ not be .isAsync ( ) and
247+ n1 = be .getStmtList ( ) .getTailExpr ( )
248+ )
232249 or
233250 n1 = n2 .( IfExpr ) .getABranch ( )
234251 or
@@ -1010,6 +1027,29 @@ private StructType inferLiteralType(LiteralExpr le) {
10101027 )
10111028}
10121029
1030+ pragma [ nomagic]
1031+ private AssociatedTypeTypeParameter getFutureOutputTypeParameter ( ) {
1032+ result .getTypeAlias ( ) = any ( FutureTrait ft ) .getOutputType ( )
1033+ }
1034+
1035+ pragma [ nomagic]
1036+ private Type inferAwaitExprType ( AwaitExpr ae , TypePath path ) {
1037+ exists ( TypePath exprPath | result = inferType ( ae .getExpr ( ) , exprPath ) |
1038+ exprPath
1039+ .isCons ( TImplTraitTypeParameter ( _, _) ,
1040+ any ( TypePath path0 | path0 .isCons ( getFutureOutputTypeParameter ( ) , path ) ) )
1041+ or
1042+ path = exprPath and
1043+ not (
1044+ exprPath = TypePath:: singleton ( TImplTraitTypeParameter ( _, _) ) and
1045+ result .( TraitType ) .getTrait ( ) instanceof FutureTrait
1046+ ) and
1047+ not exprPath
1048+ .isCons ( TImplTraitTypeParameter ( _, _) ,
1049+ any ( TypePath path0 | path0 .isCons ( getFutureOutputTypeParameter ( ) , _) ) )
1050+ )
1051+ }
1052+
10131053private module MethodCall {
10141054 /** An expression that calls a method. */
10151055 abstract private class MethodCallImpl extends Expr {
@@ -1119,12 +1159,17 @@ private predicate methodCandidateTrait(Type type, Trait trait, string name, int
11191159}
11201160
11211161private module IsInstantiationOfInput implements IsInstantiationOfInputSig< MethodCall > {
1162+ pragma [ nomagic]
1163+ private predicate isMethodCall ( MethodCall mc , Type rootType , string name , int arity ) {
1164+ rootType = mc .getTypeAt ( TypePath:: nil ( ) ) and
1165+ name = mc .getMethodName ( ) and
1166+ arity = mc .getArity ( )
1167+ }
1168+
11221169 pragma [ nomagic]
11231170 predicate potentialInstantiationOf ( MethodCall mc , TypeAbstraction impl , TypeMention constraint ) {
11241171 exists ( Type rootType , string name , int arity |
1125- rootType = mc .getTypeAt ( TypePath:: nil ( ) ) and
1126- name = mc .getMethodName ( ) and
1127- arity = mc .getArity ( ) and
1172+ isMethodCall ( mc , rootType , name , arity ) and
11281173 constraint = impl .( ImplTypeAbstraction ) .getSelfTy ( )
11291174 |
11301175 methodCandidateTrait ( rootType , mc .getTrait ( ) , name , arity , impl )
@@ -1161,6 +1206,12 @@ private Function getMethodFromImpl(MethodCall mc) {
11611206 )
11621207}
11631208
1209+ bindingset [ trait, name]
1210+ pragma [ inline_late]
1211+ private Function getTraitMethod ( TraitType trait , string name ) {
1212+ result = getMethodSuccessor ( trait .getTrait ( ) , name )
1213+ }
1214+
11641215/**
11651216 * Gets a method that the method call `mc` resolves to based on type inference,
11661217 * if any.
@@ -1172,6 +1223,11 @@ private Function inferMethodCallTarget(MethodCall mc) {
11721223 // The type of the receiver is a type parameter and the method comes from a
11731224 // trait bound on the type parameter.
11741225 result = getTypeParameterMethod ( mc .getTypeAt ( TypePath:: nil ( ) ) , mc .getMethodName ( ) )
1226+ or
1227+ // The type of the receiver is an `impl Trait` type.
1228+ result =
1229+ getTraitMethod ( mc .getTypeAt ( TypePath:: singleton ( TImplTraitTypeParameter ( _, _) ) ) ,
1230+ mc .getMethodName ( ) )
11751231}
11761232
11771233cached
@@ -1347,6 +1403,8 @@ private module Cached {
13471403 or
13481404 result = inferLiteralType ( n ) and
13491405 path .isEmpty ( )
1406+ or
1407+ result = inferAwaitExprType ( n , path )
13501408 }
13511409}
13521410
@@ -1363,7 +1421,7 @@ private module Debug {
13631421 exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
13641422 result .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
13651423 filepath .matches ( "%/main.rs" ) and
1366- startline = 948
1424+ startline = 1334
13671425 )
13681426 }
13691427
0 commit comments