Skip to content

Commit dc747e5

Browse files
committed
wip6
1 parent f65e02c commit dc747e5

2 files changed

Lines changed: 12 additions & 27 deletions

File tree

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

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ private module Input3 implements InputSig3 {
525525
final class Invocation = InvocationImpl;
526526

527527
abstract private class InvocationImpl extends Expr {
528-
abstract TypeMention getTypeQualifier();
528+
abstract Type getTypeQualifier(TypePath path);
529529

530530
abstract Type getTypeArgument(int pos, TypePath path);
531531

@@ -542,7 +542,9 @@ private module Input3 implements InputSig3 {
542542

543543
private class AssocFunctionCall extends InvocationImpl instanceof AssocFunctionResolution::AssocFunctionCall
544544
{
545-
override TypeMention getTypeQualifier() { result = getCallExprTypeArgument2(this) }
545+
override Type getTypeQualifier(TypePath path) {
546+
result = getCallExprTypeQualifier(this, path, _)
547+
}
546548

547549
pragma[nomagic]
548550
override Type getTypeArgument(int pos, TypePath path) {
@@ -589,7 +591,7 @@ private module Input3 implements InputSig3 {
589591
private class NonAssocFunctionCall extends InvocationImpl instanceof NonAssocCallExpr,
590592
CallExprImpl::CallExprCall
591593
{
592-
override TypeMention getTypeQualifier() { none() }
594+
override Type getTypeQualifier(TypePath path) { none() }
593595

594596
pragma[nomagic]
595597
override Type getTypeArgument(int pos, TypePath path) {
@@ -627,7 +629,9 @@ private module Input3 implements InputSig3 {
627629
this instanceof CallExprImpl::TupleVariantExpr
628630
}
629631

630-
override TypeMention getTypeQualifier() { result = CallExprImpl::getFunctionPath(this) }
632+
override Type getTypeQualifier(TypePath path) {
633+
result = CallExprImpl::getFunctionPath(this).(TypeMention).getTypeAt(path)
634+
}
631635

632636
override Type getTypeArgument(int pos, TypePath path) {
633637
// result = NonAssocCallExpr.super.getTypeArgument(pos, path)
@@ -648,9 +652,9 @@ private module Input3 implements InputSig3 {
648652
pragma[nomagic]
649653
override Constructor getTarget() { result = resolvePath(super.getPath()) }
650654

651-
override TypeMention getTypeQualifier() {
655+
override Type getTypeQualifier(TypePath path) {
652656
// Handle constructions that use `Self {...}` syntax
653-
result = super.getPath()
657+
result = super.getPath().(TypeMention).getTypeAt(path)
654658
}
655659

656660
pragma[nomagic]
@@ -1149,25 +1153,6 @@ private Type getCallExprTypeArgument(CallExpr ce, int pos, TypePath path) {
11491153
)
11501154
}
11511155

1152-
pragma[nomagic]
1153-
private TypeMention getCallExprTypeArgument2(CallExpr ce) {
1154-
exists(Path p | p = CallExprImpl::getFunctionPath(ce) |
1155-
exists(Path qualifier |
1156-
qualifier = p.getQualifier() and
1157-
not result.getType() instanceof TraitType
1158-
|
1159-
result = qualifier
1160-
or
1161-
// `<Foo as Bar>::baz()`; `Foo` is the type qualifier
1162-
exists(PathSegment segment |
1163-
segment = qualifier.getSegment() and
1164-
result = segment.getTypeRepr() and
1165-
segment.hasTraitTypeRepr()
1166-
)
1167-
)
1168-
)
1169-
}
1170-
11711156
/**
11721157
* Holds if `me` is a call to the `panic!` macro.
11731158
*

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
21682168
*/
21692169
AstNode getArgument(int i);
21702170

2171-
TypeMention getTypeQualifier();
2171+
Type getTypeQualifier(TypePath path);
21722172

21732173
/** Gets the target of this invocation in the given resolution context. */
21742174
Parameterizable getTargetForTypeQualifierMatching();
@@ -2926,7 +2926,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
29262926

29272927
final class Access extends InvocationFinal {
29282928
Type getInferredType(AccessPosition apos, TypePath path) {
2929-
result = this.getTypeQualifier().getTypeAt(path) and
2929+
result = this.getTypeQualifier(path) and
29302930
exists(apos)
29312931
}
29322932

0 commit comments

Comments
 (0)