@@ -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 )
@@ -232,8 +245,12 @@ private predicate typeEquality(AstNode n1, TypePath path1, AstNode n2, TypePath
232245 n1 = n2 .( ParenExpr ) .getExpr ( ) and
233246 path1 = path2
234247 or
235- n1 = n2 .( BlockExpr ) .getStmtList ( ) .getTailExpr ( ) and
236- path1 = path2
248+ n2 =
249+ any ( BlockExpr be |
250+ not be .isAsync ( ) and
251+ n1 = be .getStmtList ( ) .getTailExpr ( ) and
252+ path1 = path2
253+ )
237254 or
238255 n1 = n2 .( IfExpr ) .getABranch ( ) and
239256 path1 = path2
@@ -998,6 +1015,29 @@ private StructType inferLiteralType(LiteralExpr le) {
9981015 )
9991016}
10001017
1018+ pragma [ nomagic]
1019+ private AssociatedTypeTypeParameter getFutureOutputTypeParameter ( ) {
1020+ result .getTypeAlias ( ) = any ( FutureTrait ft ) .getOutputType ( )
1021+ }
1022+
1023+ pragma [ nomagic]
1024+ private Type inferAwaitExprType ( AwaitExpr ae , TypePath path ) {
1025+ exists ( TypePath exprPath | result = inferType ( ae .getExpr ( ) , exprPath ) |
1026+ exprPath
1027+ .isCons ( TImplTraitTypeParameter ( _, _) ,
1028+ any ( TypePath path0 | path0 .isCons ( getFutureOutputTypeParameter ( ) , path ) ) )
1029+ or
1030+ path = exprPath and
1031+ not (
1032+ exprPath = TypePath:: singleton ( TImplTraitTypeParameter ( _, _) ) and
1033+ result .( TraitType ) .getTrait ( ) instanceof FutureTrait
1034+ ) and
1035+ not exprPath
1036+ .isCons ( TImplTraitTypeParameter ( _, _) ,
1037+ any ( TypePath path0 | path0 .isCons ( getFutureOutputTypeParameter ( ) , _) ) )
1038+ )
1039+ }
1040+
10011041private module MethodCall {
10021042 /** An expression that calls a method. */
10031043 abstract private class MethodCallImpl extends Expr {
@@ -1087,12 +1127,17 @@ private predicate methodCandidateTrait(Type type, Trait trait, string name, int
10871127}
10881128
10891129private module IsInstantiationOfInput implements IsInstantiationOfInputSig< MethodCall > {
1130+ pragma [ nomagic]
1131+ private predicate isMethodCall ( MethodCall mc , Type rootType , string name , int arity ) {
1132+ rootType = mc .getTypeAt ( TypePath:: nil ( ) ) and
1133+ name = mc .getMethodName ( ) and
1134+ arity = mc .getArity ( )
1135+ }
1136+
10901137 pragma [ nomagic]
10911138 predicate potentialInstantiationOf ( MethodCall mc , TypeAbstraction impl , TypeMention constraint ) {
10921139 exists ( Type rootType , string name , int arity |
1093- rootType = mc .getTypeAt ( TypePath:: nil ( ) ) and
1094- name = mc .getMethodName ( ) and
1095- arity = mc .getArity ( ) and
1140+ isMethodCall ( mc , rootType , name , arity ) and
10961141 constraint = impl .( ImplTypeAbstraction ) .getSelfTy ( )
10971142 |
10981143 methodCandidateTrait ( rootType , mc .getTrait ( ) , name , arity , impl )
@@ -1129,6 +1174,12 @@ private Function getMethodFromImpl(MethodCall mc) {
11291174 )
11301175}
11311176
1177+ bindingset [ trait, name]
1178+ pragma [ inline_late]
1179+ private Function getTraitMethod ( TraitType trait , string name ) {
1180+ result = getMethodSuccessor ( trait .getTrait ( ) , name )
1181+ }
1182+
11321183/**
11331184 * Gets a method that the method call `mc` resolves to based on type inference,
11341185 * if any.
@@ -1140,6 +1191,11 @@ private Function inferMethodCallTarget(MethodCall mc) {
11401191 // The type of the receiver is a type parameter and the method comes from a
11411192 // trait bound on the type parameter.
11421193 result = getTypeParameterMethod ( mc .getTypeAt ( TypePath:: nil ( ) ) , mc .getMethodName ( ) )
1194+ or
1195+ // The type of the receiver is an `impl Trait` type.
1196+ result =
1197+ getTraitMethod ( mc .getTypeAt ( TypePath:: singleton ( TImplTraitTypeParameter ( _, _) ) ) ,
1198+ mc .getMethodName ( ) )
11431199}
11441200
11451201cached
@@ -1315,6 +1371,8 @@ private module Cached {
13151371 or
13161372 result = inferLiteralType ( n ) and
13171373 path .isEmpty ( )
1374+ or
1375+ result = inferAwaitExprType ( n , path )
13181376 }
13191377}
13201378
@@ -1331,7 +1389,7 @@ private module Debug {
13311389 exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
13321390 result .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
13331391 filepath .matches ( "%/main.rs" ) and
1334- startline = 948
1392+ startline = 1334
13351393 )
13361394 }
13371395
0 commit comments