@@ -354,19 +354,6 @@ private Type inferImplicitSelfType(SelfParam self, TypePath path) {
354
354
)
355
355
}
356
356
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
-
370
357
/**
371
358
* A matching configuration for resolving types of struct expressions
372
359
* like `Foo { bar = baz }`.
@@ -453,9 +440,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
453
440
class AccessPosition = DeclarationPosition ;
454
441
455
442
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 ( ) }
459
444
460
445
AstNode getNodeAt ( AccessPosition apos ) {
461
446
result = this .getFieldExpr ( apos .asFieldPos ( ) ) .getExpr ( )
@@ -466,6 +451,17 @@ private module StructExprMatchingInput implements MatchingInputSig {
466
451
467
452
Type getInferredType ( AccessPosition apos , TypePath path ) {
468
453
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
+ )
469
465
}
470
466
471
467
Declaration getTarget ( ) { result = resolvePath ( this .getPath ( ) ) }
@@ -538,15 +534,24 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
538
534
539
535
abstract Type getReturnType ( TypePath path ) ;
540
536
541
- final Type getDeclaredType ( DeclarationPosition dpos , TypePath path ) {
537
+ Type getDeclaredType ( DeclarationPosition dpos , TypePath path ) {
542
538
result = this .getParameterType ( dpos , path )
543
539
or
544
540
dpos .isReturn ( ) and
545
541
result = this .getReturnType ( path )
546
542
}
547
543
}
548
544
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 {
550
555
TupleStructDecl ( ) { this .isTuple ( ) }
551
556
552
557
override TypeParameter getTypeParameter ( TypeParameterPosition ppos ) {
@@ -569,7 +574,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
569
574
}
570
575
}
571
576
572
- private class TupleVariantDecl extends Declaration , Variant {
577
+ private class TupleVariantDecl extends TupleDeclaration , Variant {
573
578
TupleVariantDecl ( ) { this .isTuple ( ) }
574
579
575
580
override TypeParameter getTypeParameter ( TypeParameterPosition ppos ) {
@@ -698,9 +703,14 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
698
703
private import codeql.rust.elements.internal.CallExprImpl:: Impl as CallExprImpl
699
704
700
705
final class Access extends Call {
706
+ pragma [ nomagic]
701
707
Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
702
708
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
+ )
704
714
or
705
715
arg =
706
716
this .( MethodCallExpr ) .getGenericArgList ( ) .getTypeArg ( apos .asMethodTypeArgumentPosition ( ) )
0 commit comments