Skip to content

Commit 78c262c

Browse files
authored
Merge pull request #21297 from hvitved/rust/type-inference-fix-bug
Rust: Fix bug in `inferMethodCallTypeSelf`
2 parents c3ac202 + 6611978 commit 78c262c

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ class DerefImplItemNode extends ImplItemNode {
2020
Type resolveSelfTypeAt(TypePath path) { result = resolveImplSelfTypeAt(this, path) }
2121

2222
/**
23-
* Holds if the target type of the dereference implemention mentions a type
24-
* parameter at `path`.
23+
* Holds if the target type of the dereference implementation mentions type
24+
* parameter `tp` at `path`.
2525
*/
2626
pragma[nomagic]
27-
predicate targetHasTypeParameterAt(TypePath path) {
28-
this.getAssocItem("Target").(TypeAlias).getTypeRepr().(TypeMention).getTypeAt(path) instanceof
29-
TypeParameter
27+
predicate targetHasTypeParameterAt(TypePath path, TypeParameter tp) {
28+
tp = this.getAssocItem("Target").(TypeAlias).getTypeRepr().(TypeMention).getTypeAt(path)
3029
}
3130

3231
/** Gets the first type parameter of the type being implemented, if any. */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2642,7 +2642,7 @@ private Type inferMethodCallTypeSelf(
26422642
not result instanceof TypeParameter
26432643
or
26442644
exists(TypePath pathToTypeParam, TypePath suffix |
2645-
impl.targetHasTypeParameterAt(pathToTypeParam) and
2645+
impl.targetHasTypeParameterAt(pathToTypeParam, selfParamType) and
26462646
path0 = pathToTypeParam.appendInverse(suffix) and
26472647
result = t0 and
26482648
path = selfPath.append(suffix)

0 commit comments

Comments
 (0)