Skip to content

Commit adfced0

Browse files
committed
perf
1 parent 77fa7b4 commit adfced0

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

rust/ql/lib/codeql/rust/internal/TypeInference.qll

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,20 +1411,35 @@ private module MethodCallResolution {
14111411
else any()
14121412
}
14131413

1414+
pragma[nomagic]
1415+
private Type inferPositionalArgumentType(FunctionPosition pos, TypePath path) {
1416+
pos.isPositional() and
1417+
result = inferType(mc_.getArgument(pos.asArgumentPosition()), path)
1418+
}
1419+
1420+
pragma[nomagic]
1421+
private Function resolveAmbigousCallTargetCand(FunctionPosition pos, TypePath path, Type type) {
1422+
exists(ImplOrTraitItemNode i, string name |
1423+
result = this.resolveCallTargetCand(i, name) and
1424+
FunctionOverloading::functionResolutionDependsOnArgument(i, name, result, pos, path, type)
1425+
)
1426+
}
1427+
14141428
/** Gets a method that matches this method call. */
14151429
pragma[nomagic]
14161430
Function resolveCallTarget() {
1417-
exists(ImplOrTraitItemNode i, string name | result = this.resolveCallTargetCand(i, name) |
1418-
not FunctionOverloading::functionResolutionDependsOnArgument(i, name, _,
1419-
any(FunctionPosition pos | pos.isPositional()), _, _)
1420-
or
1421-
exists(FunctionPosition pos, TypePath path, Type type |
1422-
FunctionOverloading::functionResolutionDependsOnArgument(i, name, result, pos,
1423-
pragma[only_bind_into](path), type) and
1424-
pos.isPositional() and
1425-
inferType(mc_.getArgument(pos.asArgumentPosition()), pragma[only_bind_into](path)) = type
1431+
exists(ImplOrTraitItemNode i, string name |
1432+
result = this.resolveCallTargetCand(i, name) and
1433+
not exists(FunctionPosition pos |
1434+
FunctionOverloading::functionResolutionDependsOnArgument(i, name, _, pos, _, _) and
1435+
pos.isPositional()
14261436
)
14271437
)
1438+
or
1439+
exists(FunctionPosition pos, TypePath path, Type type |
1440+
result = this.resolveAmbigousCallTargetCand(pos, path, type) and
1441+
type = this.inferPositionalArgumentType(pos, path)
1442+
)
14281443
}
14291444

14301445
string toString() { result = mc_.toString() + " [" + derefChainBorrow + "]" }

0 commit comments

Comments
 (0)