Rust: Minor refactoring of type inference

This commit is contained in:
Simon Friis Vindum
2025-03-15 13:47:08 +01:00
parent 210b4db908
commit 422d9e1f93
2 changed files with 9 additions and 14 deletions

View File

@@ -578,14 +578,9 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
}
Declaration getTarget() {
result =
[
CallExprImpl::getResolvedFunction(this).(AstNode),
this.(CallExpr).getStruct(),
this.(CallExpr).getVariant(),
// mutual recursion; resolving method calls requires resolving types and vice versa
resolveMethodCallExpr(this)
]
result = CallExprImpl::getResolvedFunction(this)
or
result = resolveMethodCallExpr(this) // mutual recursion; resolving method calls requires resolving types and vice versa
}
}

View File

@@ -538,11 +538,11 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
private predicate directTypeMatch(
Access a, Declaration target, TypePath path, Type t, TypeParameter tp
) {
not exists(getTypeArgument(a, target, tp, _)) and
exists(AccessPosition apos, DeclarationPosition dpos, TypePath pathToTypeParam |
adjustedAccessType(a, apos, target, pathToTypeParam.append(path), t) and
accessDeclarationPositionMatch(apos, dpos) and
tp = target.getDeclaredType(dpos, pathToTypeParam) and
not exists(getTypeArgument(a, target, tp, _)) and
accessDeclarationPositionMatch(apos, dpos)
adjustedAccessType(a, apos, target, pathToTypeParam.append(path), t)
)
}
@@ -667,10 +667,10 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
private predicate baseTypeMatch(
Access a, Declaration target, TypePath path, Type t, TypeParameter tp
) {
not exists(getTypeArgument(a, target, tp, _)) and
exists(AccessPosition apos, DeclarationPosition dpos, Type base, TypePath pathToTypeParam |
accessBaseType(a, apos, target, base, pathToTypeParam.append(path), t) and
declarationBaseType(target, dpos, base, pathToTypeParam, tp) and
not exists(getTypeArgument(a, target, tp, _)) and
accessDeclarationPositionMatch(apos, dpos)
)
}
@@ -744,8 +744,8 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
exists(DeclarationPosition dpos | accessDeclarationPositionMatch(apos, dpos) |
exists(Declaration target, TypePath prefix, TypeParameter tp, TypePath suffix |
tp = target.getDeclaredType(pragma[only_bind_into](dpos), prefix) and
typeMatch(a, target, suffix, result, tp) and
path = prefix.append(suffix)
path = prefix.append(suffix) and
typeMatch(a, target, suffix, result, tp)
)
or
exists(Declaration target |