Skip to content

Commit 0699028

Browse files
committed
Rust: Handle functions in dependencies not having parameters
1 parent d498eb0 commit 0699028

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -965,20 +965,25 @@ private module Cached {
965965

966966
/** Holds if a method for `type` with the name `name` and the arity `arity` exists in `impl`. */
967967
pragma[nomagic]
968-
private predicate methodCandidate(Type type, string name, int arity, Impl impl) {
968+
private predicate methodCandidate(Type type, string name, Impl impl, Function f) {
969969
type = impl.(ImplTypeAbstraction).getSelfTy().(TypeReprMention).resolveType() and
970-
exists(Function f |
971-
f = impl.(ImplItemNode).getASuccessor(name) and
972-
f.getParamList().hasSelfParam() and
973-
arity = f.getParamList().getNumberOfParams()
974-
)
970+
f = impl.(ImplItemNode).getASuccessor(name)
975971
}
976972

977973
private module IsInstantiationOfInput implements IsInstantiationOfSig<ReceiverExpr> {
978974
predicate potentialInstantiationOf(ReceiverExpr receiver, TypeAbstraction impl, TypeMention sub) {
979-
methodCandidate(receiver.resolveTypeAt(TypePath::nil()), receiver.getField(),
980-
receiver.getNumberOfArgs(), impl) and
981-
sub = impl.(ImplTypeAbstraction).getSelfTy()
975+
exists(Function method |
976+
methodCandidate(receiver.resolveTypeAt(TypePath::nil()), receiver.getField(), impl, method) and
977+
(
978+
method.getParamList().getNumberOfParams() = receiver.getNumberOfArgs() and
979+
method.getParamList().hasSelfParam()
980+
or
981+
// TODO: Once parameter lists for functions in dependencies are
982+
// extracted correctly we should check arity for those as well.
983+
not method.fromSource()
984+
) and
985+
sub = impl.(ImplTypeAbstraction).getSelfTy()
986+
)
982987
}
983988
}
984989

0 commit comments

Comments
 (0)