Skip to content

Commit 422d9e1

Browse files
committed
Rust: Minor refactoring of type inference
1 parent 210b4db commit 422d9e1

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -578,14 +578,9 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
578578
}
579579

580580
Declaration getTarget() {
581-
result =
582-
[
583-
CallExprImpl::getResolvedFunction(this).(AstNode),
584-
this.(CallExpr).getStruct(),
585-
this.(CallExpr).getVariant(),
586-
// mutual recursion; resolving method calls requires resolving types and vice versa
587-
resolveMethodCallExpr(this)
588-
]
581+
result = CallExprImpl::getResolvedFunction(this)
582+
or
583+
result = resolveMethodCallExpr(this) // mutual recursion; resolving method calls requires resolving types and vice versa
589584
}
590585
}
591586

shared/typeinference/codeql/typeinference/internal/TypeInference.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,11 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
538538
private predicate directTypeMatch(
539539
Access a, Declaration target, TypePath path, Type t, TypeParameter tp
540540
) {
541+
not exists(getTypeArgument(a, target, tp, _)) and
541542
exists(AccessPosition apos, DeclarationPosition dpos, TypePath pathToTypeParam |
542-
adjustedAccessType(a, apos, target, pathToTypeParam.append(path), t) and
543+
accessDeclarationPositionMatch(apos, dpos) and
543544
tp = target.getDeclaredType(dpos, pathToTypeParam) and
544-
not exists(getTypeArgument(a, target, tp, _)) and
545-
accessDeclarationPositionMatch(apos, dpos)
545+
adjustedAccessType(a, apos, target, pathToTypeParam.append(path), t)
546546
)
547547
}
548548

@@ -667,10 +667,10 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
667667
private predicate baseTypeMatch(
668668
Access a, Declaration target, TypePath path, Type t, TypeParameter tp
669669
) {
670+
not exists(getTypeArgument(a, target, tp, _)) and
670671
exists(AccessPosition apos, DeclarationPosition dpos, Type base, TypePath pathToTypeParam |
671672
accessBaseType(a, apos, target, base, pathToTypeParam.append(path), t) and
672673
declarationBaseType(target, dpos, base, pathToTypeParam, tp) and
673-
not exists(getTypeArgument(a, target, tp, _)) and
674674
accessDeclarationPositionMatch(apos, dpos)
675675
)
676676
}
@@ -744,8 +744,8 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
744744
exists(DeclarationPosition dpos | accessDeclarationPositionMatch(apos, dpos) |
745745
exists(Declaration target, TypePath prefix, TypeParameter tp, TypePath suffix |
746746
tp = target.getDeclaredType(pragma[only_bind_into](dpos), prefix) and
747-
typeMatch(a, target, suffix, result, tp) and
748-
path = prefix.append(suffix)
747+
path = prefix.append(suffix) and
748+
typeMatch(a, target, suffix, result, tp)
749749
)
750750
or
751751
exists(Declaration target |

0 commit comments

Comments
 (0)