@@ -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
@@ -1000,6 +1017,29 @@ private StructType inferLiteralType(LiteralExpr le) {
10001017 )
10011018}
10021019
1020+ pragma [ nomagic]
1021+ private AssociatedTypeTypeParameter getFutureOutputTypeParameter ( ) {
1022+ result .getTypeAlias ( ) = any ( FutureTrait ft ) .getOutputType ( )
1023+ }
1024+
1025+ pragma [ nomagic]
1026+ private Type inferAwaitExprType ( AwaitExpr ae , TypePath path ) {
1027+ exists ( TypePath exprPath | result = inferType ( ae .getExpr ( ) , exprPath ) |
1028+ exprPath
1029+ .isCons ( TImplTraitTypeParameter ( _, _) ,
1030+ any ( TypePath path0 | path0 .isCons ( getFutureOutputTypeParameter ( ) , path ) ) )
1031+ or
1032+ path = exprPath and
1033+ not (
1034+ exprPath = TypePath:: singleton ( TImplTraitTypeParameter ( _, _) ) and
1035+ result .( TraitType ) .getTrait ( ) instanceof FutureTrait
1036+ ) and
1037+ not exprPath
1038+ .isCons ( TImplTraitTypeParameter ( _, _) ,
1039+ any ( TypePath path0 | path0 .isCons ( getFutureOutputTypeParameter ( ) , _) ) )
1040+ )
1041+ }
1042+
10031043private module MethodCall {
10041044 /** An expression that calls a method. */
10051045 abstract private class MethodCallImpl extends Expr {
@@ -1089,12 +1129,17 @@ private predicate methodCandidateTrait(Type type, Trait trait, string name, int
10891129}
10901130
10911131private module IsInstantiationOfInput implements IsInstantiationOfInputSig< MethodCall > {
1132+ pragma [ nomagic]
1133+ private predicate isMethodCall ( MethodCall mc , Type rootType , string name , int arity ) {
1134+ rootType = mc .getTypeAt ( TypePath:: nil ( ) ) and
1135+ name = mc .getMethodName ( ) and
1136+ arity = mc .getArity ( )
1137+ }
1138+
10921139 pragma [ nomagic]
10931140 predicate potentialInstantiationOf ( MethodCall mc , TypeAbstraction impl , TypeMention constraint ) {
10941141 exists ( Type rootType , string name , int arity |
1095- rootType = mc .getTypeAt ( TypePath:: nil ( ) ) and
1096- name = mc .getMethodName ( ) and
1097- arity = mc .getArity ( ) and
1142+ isMethodCall ( mc , rootType , name , arity ) and
10981143 constraint = impl .( ImplTypeAbstraction ) .getSelfTy ( )
10991144 |
11001145 methodCandidateTrait ( rootType , mc .getTrait ( ) , name , arity , impl )
@@ -1131,6 +1176,12 @@ private Function getMethodFromImpl(MethodCall mc) {
11311176 )
11321177}
11331178
1179+ bindingset [ trait, name]
1180+ pragma [ inline_late]
1181+ private Function getTraitMethod ( TraitType trait , string name ) {
1182+ result = getMethodSuccessor ( trait .getTrait ( ) , name )
1183+ }
1184+
11341185/**
11351186 * Gets a method that the method call `mc` resolves to based on type inference,
11361187 * if any.
@@ -1142,6 +1193,11 @@ private Function inferMethodCallTarget(MethodCall mc) {
11421193 // The type of the receiver is a type parameter and the method comes from a
11431194 // trait bound on the type parameter.
11441195 result = getTypeParameterMethod ( mc .getTypeAt ( TypePath:: nil ( ) ) , mc .getMethodName ( ) )
1196+ or
1197+ // The type of the receiver is an `impl Trait` type.
1198+ result =
1199+ getTraitMethod ( mc .getTypeAt ( TypePath:: singleton ( TImplTraitTypeParameter ( _, _) ) ) ,
1200+ mc .getMethodName ( ) )
11451201}
11461202
11471203cached
@@ -1317,6 +1373,8 @@ private module Cached {
13171373 or
13181374 result = inferLiteralType ( n ) and
13191375 path .isEmpty ( )
1376+ or
1377+ result = inferAwaitExprType ( n , path )
13201378 }
13211379}
13221380
@@ -1333,7 +1391,7 @@ private module Debug {
13331391 exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
13341392 result .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
13351393 filepath .matches ( "%/main.rs" ) and
1336- startline = 948
1394+ startline = 1334
13371395 )
13381396 }
13391397
0 commit comments