@@ -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 ( ) )
0 commit comments