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() { Declaration getTarget() {
result = result = CallExprImpl::getResolvedFunction(this)
[ or
CallExprImpl::getResolvedFunction(this).(AstNode), result = resolveMethodCallExpr(this) // mutual recursion; resolving method calls requires resolving types and vice versa
this.(CallExpr).getStruct(),
this.(CallExpr).getVariant(),
// mutual recursion; resolving method calls requires resolving types and vice versa
resolveMethodCallExpr(this)
]
} }
} }

View File

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