Skip to content

Commit 67ecb66

Browse files
committed
wip2
1 parent 0a1cc33 commit 67ecb66

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,40 +1570,40 @@ private class FunctionCallExpr extends CallExpr {
15701570
}
15711571

15721572
pragma[nomagic]
1573-
Function getAnAmbigousCandiate(ImplItemNode impl, int pos) {
1574-
exists(TraitItemNode trait, Function traitFunction |
1573+
Function getAnAmbigousCandiate(ImplItemNode impl, int pos, Function f) {
1574+
exists(TraitItemNode trait |
15751575
trait = this.getTrait() and
1576-
traitFunction = this.getResolvedFunction() and
1577-
result.implements(traitFunction) and
1576+
f = this.getResolvedFunction() and
1577+
result.implements(f) and
15781578
result = impl.getAnAssocItem()
15791579
|
15801580
assocFuncResolutionDependsOnArgument(result, impl, pos)
15811581
or
15821582
not assocFuncResolutionDependsOnArgument(result, _, _) and
1583-
traitTypeParameterOccurrence(trait, traitFunction, _, pos, _)
1583+
traitTypeParameterOccurrence(trait, f, _, pos, _)
15841584
)
15851585
or
1586-
result = this.getResolvedFunction() and
1586+
f = this.getResolvedFunction() and
1587+
result = f and
15871588
assocFuncResolutionDependsOnArgument(result, impl, pos)
15881589
}
15891590

1590-
Function getAnAmbigousCandiate(ImplItemNode impl, int pos, int rnk) {
1591-
pos = rank[rnk + 1](int pos0 | result = this.getAnAmbigousCandiate(impl, pos0) | pos0)
1591+
Function getAnAmbigousCandiate(ImplItemNode impl, int pos, Function f, int rnk) {
1592+
pos = rank[rnk + 1](int pos0 | result = this.getAnAmbigousCandiate(impl, pos0, f) | pos0)
15921593
}
15931594
}
15941595

15951596
private newtype TAmbigousAssocFunctionCallExpr =
1596-
MkAmbigousAssocFunctionCallExpr(FunctionCallExpr call, Function f, ImplItemNode impl, int pos) {
1597-
f = call.getAnAmbigousCandiate(impl, pos)
1597+
MkAmbigousAssocFunctionCallExpr(FunctionCallExpr call, Function f, int pos) {
1598+
exists(call.getAnAmbigousCandiate(_, pos, f))
15981599
}
15991600

16001601
private class AmbigousAssocFunctionCallExpr extends MkAmbigousAssocFunctionCallExpr {
16011602
FunctionCallExpr call;
16021603
Function f;
1603-
ImplItemNode impl_;
16041604
int pos;
16051605

1606-
AmbigousAssocFunctionCallExpr() { this = MkAmbigousAssocFunctionCallExpr(call, f, impl_, pos) }
1606+
AmbigousAssocFunctionCallExpr() { this = MkAmbigousAssocFunctionCallExpr(call, f, pos) }
16071607

16081608
pragma[nomagic]
16091609
Type getTypeAt(TypePath path) {
@@ -1625,7 +1625,10 @@ private module AmbigousAssocFuncIsInstantiationOfInput implements
16251625
predicate potentialInstantiationOf(
16261626
AmbigousAssocFunctionCallExpr ce, TypeAbstraction impl, TypeMention constraint
16271627
) {
1628-
exists(Function cand, int pos | ce = MkAmbigousAssocFunctionCallExpr(_, cand, impl, pos) |
1628+
exists(FunctionCallExpr call, Function f, Function cand, int pos |
1629+
ce = MkAmbigousAssocFunctionCallExpr(call, f, pos) and
1630+
cand = call.getAnAmbigousCandiate(impl, pos, f)
1631+
|
16291632
constraint = cand.getParam(pos).getTypeRepr()
16301633
or
16311634
pos = -1 and
@@ -1645,10 +1648,10 @@ private ItemNode resolveUnambigousFunctionCallTarget(FunctionCallExpr call) {
16451648

16461649
pragma[nomagic]
16471650
private Function resolveAmbigousFunctionCallTargetFromIndex(FunctionCallExpr call, int index) {
1648-
exists(Impl impl, int pos |
1651+
exists(Impl impl, int pos, Function f |
16491652
IsInstantiationOf<AmbigousAssocFunctionCallExpr, AmbigousAssocFuncIsInstantiationOfInput>::isInstantiationOf(MkAmbigousAssocFunctionCallExpr(call,
1650-
result, _, pos), impl, _) and
1651-
result = call.getAnAmbigousCandiate(impl, pos, index)
1653+
f, pos), impl, _) and
1654+
result = call.getAnAmbigousCandiate(impl, pos, f, index)
16521655
|
16531656
index = 0
16541657
or
@@ -1663,7 +1666,7 @@ pragma[nomagic]
16631666
private Function resolveAmbigousFunctionCallTarget(FunctionCallExpr call) {
16641667
result =
16651668
resolveAmbigousFunctionCallTargetFromIndex(call,
1666-
max(int index | result = call.getAnAmbigousCandiate(_, _, index)))
1669+
max(int index | result = call.getAnAmbigousCandiate(_, _, _, index)))
16671670
}
16681671

16691672
pragma[inline]

0 commit comments

Comments
 (0)