Skip to content

Commit 9403c2d

Browse files
committed
dbg
1 parent a06a902 commit 9403c2d

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
@@ -344,19 +344,6 @@ private Type inferImplicitSelfType(SelfParam self, TypePath path) {
344344
)
345345
}
346346

347-
/**
348-
* Gets any of the types mentioned in `path` that corresponds to the type
349-
* parameter `tp`.
350-
*/
351-
private TypeMention getExplicitTypeArgMention(Path path, TypeParam tp) {
352-
exists(int i |
353-
result = path.getSegment().getGenericArgList().getTypeArg(pragma[only_bind_into](i)) and
354-
tp = resolvePath(path).getTypeParam(pragma[only_bind_into](i))
355-
)
356-
or
357-
result = getExplicitTypeArgMention(path.getQualifier(), tp)
358-
}
359-
360347
/**
361348
* A matching configuration for resolving types of struct expressions
362349
* like `Foo { bar = baz }`.
@@ -443,9 +430,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
443430
class AccessPosition = DeclarationPosition;
444431

445432
class Access extends StructExpr {
446-
Type getTypeArgument(TypeArgumentPosition apos, TypePath path) {
447-
result = getExplicitTypeArgMention(this.getPath(), apos.asTypeParam()).resolveTypeAt(path)
448-
}
433+
Type getTypeArgument(TypeArgumentPosition apos, TypePath path) { none() }
449434

450435
AstNode getNodeAt(AccessPosition apos) {
451436
result = this.getFieldExpr(apos.asFieldPos()).getExpr()
@@ -456,6 +441,17 @@ private module StructExprMatchingInput implements MatchingInputSig {
456441

457442
Type getInferredType(AccessPosition apos, TypePath path) {
458443
result = inferType(this.getNodeAt(apos), path)
444+
or
445+
// The struct type is supplied explicitly as a type qualifier, e.g. TODO
446+
apos.isStructPos() and
447+
exists(TypeMention tm |
448+
// variant
449+
tm = this.getPath().getQualifier()
450+
or
451+
tm = this.getPath()
452+
|
453+
result = tm.resolveTypeAt(path)
454+
)
459455
}
460456

461457
Declaration getTarget() { result = resolvePath(this.getPath()) }
@@ -528,15 +524,24 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
528524

529525
abstract Type getReturnType(TypePath path);
530526

531-
final Type getDeclaredType(DeclarationPosition dpos, TypePath path) {
527+
Type getDeclaredType(DeclarationPosition dpos, TypePath path) {
532528
result = this.getParameterType(dpos, path)
533529
or
534530
dpos.isReturn() and
535531
result = this.getReturnType(path)
536532
}
537533
}
538534

539-
private class TupleStructDecl extends Declaration, Struct {
535+
abstract private class TupleDeclaration extends Declaration {
536+
override Type getDeclaredType(DeclarationPosition dpos, TypePath path) {
537+
result = super.getDeclaredType(dpos, path)
538+
or
539+
dpos.isSelf() and
540+
result = this.getReturnType(path)
541+
}
542+
}
543+
544+
private class TupleStructDecl extends TupleDeclaration, Struct {
540545
TupleStructDecl() { this.isTuple() }
541546

542547
override TypeParameter getTypeParameter(TypeParameterPosition ppos) {
@@ -559,7 +564,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
559564
}
560565
}
561566

562-
private class TupleVariantDecl extends Declaration, Variant {
567+
private class TupleVariantDecl extends TupleDeclaration, Variant {
563568
TupleVariantDecl() { this.isTuple() }
564569

565570
override TypeParameter getTypeParameter(TypeParameterPosition ppos) {
@@ -688,9 +693,14 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
688693
private import codeql.rust.elements.internal.CallExprImpl::Impl as CallExprImpl
689694

690695
final class Access extends Call {
696+
pragma[nomagic]
691697
Type getTypeArgument(TypeArgumentPosition apos, TypePath path) {
692698
exists(TypeMention arg | result = arg.resolveTypeAt(path) |
693-
arg = getExplicitTypeArgMention(CallExprImpl::getFunctionPath(this), apos.asTypeParam())
699+
exists(Path p, int i |
700+
p = CallExprImpl::getFunctionPath(this) and
701+
arg = p.getSegment().getGenericArgList().getTypeArg(pragma[only_bind_into](i)) and
702+
apos.asTypeParam() = resolvePath(p).getTypeParam(pragma[only_bind_into](i))
703+
)
694704
or
695705
arg =
696706
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)