From 109d802607cd156266029b38f3b773de61f46f4d Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Mon, 9 Feb 2026 14:15:05 +0100 Subject: [PATCH 1/2] Rust: Fix bug in `inferMethodCallTypeSelf` --- .../codeql/rust/internal/typeinference/DerefChain.qll | 9 ++++----- .../codeql/rust/internal/typeinference/TypeInference.qll | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/rust/ql/lib/codeql/rust/internal/typeinference/DerefChain.qll b/rust/ql/lib/codeql/rust/internal/typeinference/DerefChain.qll index 6b8c57812486..03272fe922f9 100644 --- a/rust/ql/lib/codeql/rust/internal/typeinference/DerefChain.qll +++ b/rust/ql/lib/codeql/rust/internal/typeinference/DerefChain.qll @@ -20,13 +20,12 @@ class DerefImplItemNode extends ImplItemNode { Type resolveSelfTypeAt(TypePath path) { result = resolveImplSelfTypeAt(this, path) } /** - * Holds if the target type of the dereference implemention mentions a type - * parameter at `path`. + * Holds if the target type of the dereference implemention mentions type + * parameter `tp` at `path`. */ pragma[nomagic] - predicate targetHasTypeParameterAt(TypePath path) { - this.getAssocItem("Target").(TypeAlias).getTypeRepr().(TypeMention).getTypeAt(path) instanceof - TypeParameter + predicate targetHasTypeParameterAt(TypePath path, TypeParameter tp) { + tp = this.getAssocItem("Target").(TypeAlias).getTypeRepr().(TypeMention).getTypeAt(path) } /** Gets the first type parameter of the type being implemented, if any. */ diff --git a/rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll b/rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll index e8b5c9c7a19a..ca8153f877af 100644 --- a/rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll +++ b/rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll @@ -2619,7 +2619,7 @@ private Type inferMethodCallTypeSelf( not result instanceof TypeParameter or exists(TypePath pathToTypeParam, TypePath suffix | - impl.targetHasTypeParameterAt(pathToTypeParam) and + impl.targetHasTypeParameterAt(pathToTypeParam, selfParamType) and path0 = pathToTypeParam.appendInverse(suffix) and result = t0 and path = selfPath.append(suffix) From 66119783682cf0f0c55a717278d963dd641ee452 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Mon, 9 Feb 2026 19:38:49 +0100 Subject: [PATCH 2/2] Update rust/ql/lib/codeql/rust/internal/typeinference/DerefChain.qll Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- rust/ql/lib/codeql/rust/internal/typeinference/DerefChain.qll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/ql/lib/codeql/rust/internal/typeinference/DerefChain.qll b/rust/ql/lib/codeql/rust/internal/typeinference/DerefChain.qll index 03272fe922f9..5c40f623f170 100644 --- a/rust/ql/lib/codeql/rust/internal/typeinference/DerefChain.qll +++ b/rust/ql/lib/codeql/rust/internal/typeinference/DerefChain.qll @@ -20,7 +20,7 @@ class DerefImplItemNode extends ImplItemNode { Type resolveSelfTypeAt(TypePath path) { result = resolveImplSelfTypeAt(this, path) } /** - * Holds if the target type of the dereference implemention mentions type + * Holds if the target type of the dereference implementation mentions type * parameter `tp` at `path`. */ pragma[nomagic]