Skip to content

Commit 825de5e

Browse files
committed
wip2
1 parent 7919221 commit 825de5e

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ private predicate assocFunctionInfo(
12491249
AssocFunctionType t
12501250
) {
12511251
f = i.getASuccessor(name) and
1252-
arity = f.getParamList().getNumberOfParams() and
1252+
arity = f.getNumberOfParamsInclSelf() and
12531253
t.appliesTo(f, i, pos)
12541254
}
12551255

@@ -1454,9 +1454,9 @@ private module MethodResolution {
14541454
)
14551455
}
14561456

1457-
private module MethodTraitIsVisible = TraitIsVisible<assocFunctionCallTraitCandidate/2>;
1457+
private module AssocFunctionTraitIsVisible = TraitIsVisible<assocFunctionCallTraitCandidate/2>;
14581458

1459-
private predicate methodCallVisibleTraitCandidate = MethodTraitIsVisible::traitIsVisible/2;
1459+
private predicate methodCallVisibleTraitCandidate = AssocFunctionTraitIsVisible::traitIsVisible/2;
14601460

14611461
bindingset[mc, impl]
14621462
pragma[inline_late]
@@ -1478,12 +1478,12 @@ private module MethodResolution {
14781478
bindingset[mc, strippedTypePath, strippedType]
14791479
pragma[inline_late]
14801480
private predicate methodCallNonBlanketCandidate(
1481-
MethodCall mc, Method m, FunctionPosition selfPos, ImplOrTraitItemNode i,
1481+
MethodCall mc, Function f, FunctionPosition selfPos, ImplOrTraitItemNode i,
14821482
AssocFunctionType self, TypePath strippedTypePath, Type strippedType
14831483
) {
14841484
exists(string name, int arity |
14851485
mc.hasNameAndArity(name, arity) and
1486-
assocFunctionInfoNonBlanket(m, name, arity, selfPos, i, self, strippedTypePath, strippedType)
1486+
assocFunctionInfoNonBlanket(f, name, arity, selfPos, i, self, strippedTypePath, strippedType)
14871487
|
14881488
i =
14891489
any(Impl impl |
@@ -1512,12 +1512,12 @@ private module MethodResolution {
15121512
bindingset[mc]
15131513
pragma[inline_late]
15141514
private predicate methodCallBlanketLikeCandidate(
1515-
MethodCall mc, Method m, FunctionPosition selfPos, ImplItemNode impl, AssocFunctionType self,
1515+
MethodCall mc, Function f, FunctionPosition selfPos, ImplItemNode impl, AssocFunctionType self,
15161516
TypePath blanketPath, TypeParam blanketTypeParam
15171517
) {
15181518
exists(string name, int arity |
15191519
mc.hasNameAndArity(name, arity) and
1520-
assocFunctionSelfInfoBlanketLike(m, name, arity, selfPos, impl, _, self, blanketPath,
1520+
assocFunctionSelfInfoBlanketLike(f, name, arity, selfPos, impl, _, self, blanketPath,
15211521
blanketTypeParam)
15221522
|
15231523
methodCallVisibleImplTraitCandidate(mc, impl)
@@ -1935,7 +1935,7 @@ private module MethodResolution {
19351935
* and `borrow`.
19361936
*/
19371937
pragma[nomagic]
1938-
Method resolveCallTarget(ImplOrTraitItemNode i, DerefChain derefChain, BorrowKind borrow) {
1938+
Function resolveCallTarget(ImplOrTraitItemNode i, DerefChain derefChain, BorrowKind borrow) {
19391939
exists(MethodCallCand mcc |
19401940
mcc = MkMethodCallCand(this, _, derefChain, borrow) and
19411941
result = mcc.resolveCallTarget(i)
@@ -1958,7 +1958,7 @@ private module MethodResolution {
19581958
pragma[nomagic]
19591959
override predicate hasNameAndArity(string name, int arity) {
19601960
name = super.getIdentifier().getText() and
1961-
arity = super.getArgList().getNumberOfArgs()
1961+
arity = super.getArgList().getNumberOfArgs() + 1
19621962
}
19631963

19641964
override Expr getArg(ArgumentPosition pos) {
@@ -1979,7 +1979,7 @@ private module MethodResolution {
19791979
pragma[nomagic]
19801980
override predicate hasNameAndArity(string name, int arity) {
19811981
(if this.isInMutableContext() then name = "index_mut" else name = "index") and
1982-
arity = 1
1982+
arity = 2
19831983
}
19841984

19851985
override Expr getArg(ArgumentPosition pos) {
@@ -2004,13 +2004,14 @@ private module MethodResolution {
20042004
exists(getCallExprPathQualifier(this)) and
20052005
// even if a method cannot be resolved by path resolution, it may still
20062006
// be possible to resolve a blanket implementation (so not `forex`)
2007-
forall(ItemNode i | i = CallExprImpl::getResolvedFunction(this) | i instanceof Method)
2007+
forall(ItemNode i | i = CallExprImpl::getResolvedFunction(this) | i instanceof Function)
20082008
}
20092009

20102010
pragma[nomagic]
20112011
override predicate hasNameAndArity(string name, int arity) {
2012+
// this = Debug::getRelevantLocatable() and
20122013
name = CallExprImpl::getFunctionPath(this).getText() and
2013-
arity = super.getArgList().getNumberOfArgs() - 1
2014+
arity = super.getArgList().getNumberOfArgs()
20142015
}
20152016

20162017
override Expr getArg(ArgumentPosition pos) {
@@ -2042,7 +2043,7 @@ private module MethodResolution {
20422043
pragma[nomagic]
20432044
override predicate hasNameAndArity(string name, int arity) {
20442045
super.isOverloaded(_, name, _) and
2045-
arity = super.getNumberOfOperands() - 1
2046+
arity = super.getNumberOfOperands()
20462047
}
20472048

20482049
override Expr getArg(ArgumentPosition pos) {
@@ -2099,9 +2100,9 @@ private module MethodResolution {
20992100
}
21002101

21012102
pragma[nomagic]
2102-
private Method getMethodSuccessor(ImplOrTraitItemNode i, string name, int arity) {
2103+
private Function getFunctionSuccessor(ImplOrTraitItemNode i, string name, int arity) {
21032104
result = i.getASuccessor(name) and
2104-
arity = result.getParamList().getNumberOfParams()
2105+
arity = result.getNumberOfParamsInclSelf()
21052106
}
21062107

21072108
private newtype TMethodCallCand =
@@ -2187,16 +2188,16 @@ private module MethodResolution {
21872188
}
21882189

21892190
pragma[nomagic]
2190-
Method resolveCallTargetCand(ImplOrTraitItemNode i) {
2191+
Function resolveCallTargetCand(ImplOrTraitItemNode i) {
21912192
exists(string name, int arity |
21922193
this.argIsInstantiationOf(i, name, arity) and
2193-
result = getMethodSuccessor(i, name, arity)
2194+
result = getFunctionSuccessor(i, name, arity)
21942195
)
21952196
}
21962197

2197-
/** Gets a method that matches this method call. */
2198+
/** Gets a function that matches this method call. */
21982199
pragma[nomagic]
2199-
Method resolveCallTarget(ImplOrTraitItemNode i) {
2200+
Function resolveCallTarget(ImplOrTraitItemNode i) {
22002201
result = this.resolveCallTargetCand(i) and
22012202
not FunctionOverloading::functionResolutionDependsOnArgument(i, result, _, _)
22022203
or
@@ -2316,14 +2317,14 @@ private module MethodResolution {
23162317
MethodCallCand mcc, ImplOrTraitItemNode i, AssocFunctionType selfType
23172318
) {
23182319
exists(
2319-
MethodCall mc, FunctionPosition selfPos, Method m, string name, int arity,
2320+
MethodCall mc, FunctionPosition selfPos, Function f, string name, int arity,
23202321
TypePath strippedTypePath, Type strippedType
23212322
|
23222323
mcc.hasSignature(mc, selfPos, strippedTypePath, strippedType, name, arity)
23232324
|
2324-
methodCallNonBlanketCandidate(mc, m, selfPos, i, selfType, strippedTypePath, strippedType)
2325+
methodCallNonBlanketCandidate(mc, f, selfPos, i, selfType, strippedTypePath, strippedType)
23252326
or
2326-
methodCallBlanketLikeCandidate(mc, m, selfPos, i, selfType, _, _) and
2327+
methodCallBlanketLikeCandidate(mc, f, selfPos, i, selfType, _, _) and
23272328
ReceiverSatisfiesBlanketLikeConstraint::satisfiesBlanketConstraint(mcc, i)
23282329
)
23292330
}

0 commit comments

Comments
 (0)