Skip to content

Commit 99bc945

Browse files
committed
dbg
1 parent 165aae3 commit 99bc945

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

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

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -354,19 +354,6 @@ private Type inferImplicitSelfType(SelfParam self, TypePath path) {
354354
)
355355
}
356356

357-
/**
358-
* Gets any of the types mentioned in `path` that corresponds to the type
359-
* parameter `tp`.
360-
*/
361-
private TypeMention getExplicitTypeArgMention(Path path, TypeParam tp) {
362-
exists(int i |
363-
result = path.getSegment().getGenericArgList().getTypeArg(pragma[only_bind_into](i)) and
364-
tp = resolvePath(path).getTypeParam(pragma[only_bind_into](i))
365-
)
366-
or
367-
result = getExplicitTypeArgMention(path.getQualifier(), tp)
368-
}
369-
370357
/**
371358
* A matching configuration for resolving types of struct expressions
372359
* like `Foo { bar = baz }`.
@@ -453,9 +440,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
453440
class AccessPosition = DeclarationPosition;
454441

455442
class Access extends StructExpr {
456-
Type getTypeArgument(TypeArgumentPosition apos, TypePath path) {
457-
result = getExplicitTypeArgMention(this.getPath(), apos.asTypeParam()).resolveTypeAt(path)
458-
}
443+
Type getTypeArgument(TypeArgumentPosition apos, TypePath path) { none() }
459444

460445
AstNode getNodeAt(AccessPosition apos) {
461446
result = this.getFieldExpr(apos.asFieldPos()).getExpr()
@@ -466,6 +451,17 @@ private module StructExprMatchingInput implements MatchingInputSig {
466451

467452
Type getInferredType(AccessPosition apos, TypePath path) {
468453
result = inferType(this.getNodeAt(apos), path)
454+
or
455+
// The struct type is supplied explicitly as a type qualifier, e.g. TODO
456+
apos.isStructPos() and
457+
exists(TypeMention tm |
458+
// variant
459+
tm = this.getPath().getQualifier()
460+
or
461+
tm = this.getPath()
462+
|
463+
result = tm.resolveTypeAt(path)
464+
)
469465
}
470466

471467
Declaration getTarget() { result = resolvePath(this.getPath()) }
@@ -538,15 +534,24 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
538534

539535
abstract Type getReturnType(TypePath path);
540536

541-
final Type getDeclaredType(DeclarationPosition dpos, TypePath path) {
537+
Type getDeclaredType(DeclarationPosition dpos, TypePath path) {
542538
result = this.getParameterType(dpos, path)
543539
or
544540
dpos.isReturn() and
545541
result = this.getReturnType(path)
546542
}
547543
}
548544

549-
private class TupleStructDecl extends Declaration, Struct {
545+
abstract private class TupleDeclaration extends Declaration {
546+
override Type getDeclaredType(DeclarationPosition dpos, TypePath path) {
547+
result = super.getDeclaredType(dpos, path)
548+
or
549+
dpos.isSelf() and
550+
result = this.getReturnType(path)
551+
}
552+
}
553+
554+
private class TupleStructDecl extends TupleDeclaration, Struct {
550555
TupleStructDecl() { this.isTuple() }
551556

552557
override TypeParameter getTypeParameter(TypeParameterPosition ppos) {
@@ -569,7 +574,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
569574
}
570575
}
571576

572-
private class TupleVariantDecl extends Declaration, Variant {
577+
private class TupleVariantDecl extends TupleDeclaration, Variant {
573578
TupleVariantDecl() { this.isTuple() }
574579

575580
override TypeParameter getTypeParameter(TypeParameterPosition ppos) {
@@ -698,9 +703,14 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
698703
private import codeql.rust.elements.internal.CallExprImpl::Impl as CallExprImpl
699704

700705
final class Access extends Call {
706+
pragma[nomagic]
701707
Type getTypeArgument(TypeArgumentPosition apos, TypePath path) {
702708
exists(TypeMention arg | result = arg.resolveTypeAt(path) |
703-
arg = getExplicitTypeArgMention(CallExprImpl::getFunctionPath(this), apos.asTypeParam())
709+
exists(Path p, int i |
710+
p = CallExprImpl::getFunctionPath(this) and
711+
arg = p.getSegment().getGenericArgList().getTypeArg(pragma[only_bind_into](i)) and
712+
apos.asTypeParam() = resolvePath(p).getTypeParam(pragma[only_bind_into](i))
713+
)
704714
or
705715
arg =
706716
this.(MethodCallExpr).getGenericArgList().getTypeArg(apos.asMethodTypeArgumentPosition())

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class PathTypeMention extends TypeMention, Path {
8585
// If a type argument is not given in the path, then we use the default for
8686
// the type parameter if one exists for the type.
8787
not exists(this.getSegment().getGenericArgList().getTypeArg(i)) and
88-
result = this.resolveType().getTypeParameterDefault(i)
88+
result = this.resolveType().getTypeParameterDefault(i) and
89+
this = any(PathTypeRepr ptp).getPath().getQualifier*()
8990
or
9091
// `Self` paths inside `impl` blocks have implicit type arguments that are
9192
// the type parameters of the `impl` block. For example, in

0 commit comments

Comments
 (0)