@@ -344,19 +344,6 @@ private Type inferImplicitSelfType(SelfParam self, TypePath path) {
344
344
)
345
345
}
346
346
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
-
360
347
/**
361
348
* A matching configuration for resolving types of struct expressions
362
349
* like `Foo { bar = baz }`.
@@ -443,9 +430,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
443
430
class AccessPosition = DeclarationPosition ;
444
431
445
432
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 ( ) }
449
434
450
435
AstNode getNodeAt ( AccessPosition apos ) {
451
436
result = this .getFieldExpr ( apos .asFieldPos ( ) ) .getExpr ( )
@@ -456,6 +441,17 @@ private module StructExprMatchingInput implements MatchingInputSig {
456
441
457
442
Type getInferredType ( AccessPosition apos , TypePath path ) {
458
443
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
+ )
459
455
}
460
456
461
457
Declaration getTarget ( ) { result = resolvePath ( this .getPath ( ) ) }
@@ -528,15 +524,24 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
528
524
529
525
abstract Type getReturnType ( TypePath path ) ;
530
526
531
- final Type getDeclaredType ( DeclarationPosition dpos , TypePath path ) {
527
+ Type getDeclaredType ( DeclarationPosition dpos , TypePath path ) {
532
528
result = this .getParameterType ( dpos , path )
533
529
or
534
530
dpos .isReturn ( ) and
535
531
result = this .getReturnType ( path )
536
532
}
537
533
}
538
534
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 {
540
545
TupleStructDecl ( ) { this .isTuple ( ) }
541
546
542
547
override TypeParameter getTypeParameter ( TypeParameterPosition ppos ) {
@@ -559,7 +564,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
559
564
}
560
565
}
561
566
562
- private class TupleVariantDecl extends Declaration , Variant {
567
+ private class TupleVariantDecl extends TupleDeclaration , Variant {
563
568
TupleVariantDecl ( ) { this .isTuple ( ) }
564
569
565
570
override TypeParameter getTypeParameter ( TypeParameterPosition ppos ) {
@@ -688,9 +693,14 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
688
693
private import codeql.rust.elements.internal.CallExprImpl:: Impl as CallExprImpl
689
694
690
695
final class Access extends Call {
696
+ pragma [ nomagic]
691
697
Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
692
698
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
+ )
694
704
or
695
705
arg =
696
706
this .( MethodCallExpr ) .getGenericArgList ( ) .getTypeArg ( apos .asMethodTypeArgumentPosition ( ) )
0 commit comments