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