Merge pull request #21297 from hvitved/rust/type-inference-fix-bug

Rust: Fix bug in `inferMethodCallTypeSelf`
This commit is contained in:
Simon Friis Vindum
2026-02-10 09:51:12 +01:00
committed by GitHub
2 changed files with 5 additions and 6 deletions

View File

@@ -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 implementation 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. */

View File

@@ -2642,7 +2642,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)