@@ -80,10 +80,18 @@ private module Input1 implements InputSig1<Location> {
8080 int getTypeParameterId ( TypeParameter tp ) {
8181 tp =
8282 rank [ result ] ( TypeParameter tp0 , int kind , int id |
83- tp0 instanceof RefTypeParameter and
83+ tp0 instanceof ArrayTypeParameter and
8484 kind = 0 and
8585 id = 0
8686 or
87+ tp0 instanceof RefTypeParameter and
88+ kind = 0 and
89+ id = 1
90+ or
91+ tp0 instanceof SliceTypeParameter and
92+ kind = 0 and
93+ id = 2
94+ or
8795 kind = 1 and
8896 exists ( AstNode node | id = idOfTypeParameterAstNode ( node ) |
8997 node = tp0 .( TypeParamTypeParameter ) .getTypeParam ( ) or
@@ -569,7 +577,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
569577 exists ( Param p , int i , boolean inMethod |
570578 paramPos ( this .getParamList ( ) , p , i , inMethod ) and
571579 dpos = TPositionalDeclarationPosition ( i , inMethod ) and
572- result = inferAnnotatedType ( p . getPat ( ) , path )
580+ result = p . getTypeRepr ( ) . ( TypeMention ) . resolveTypeAt ( path )
573581 )
574582 or
575583 exists ( SelfParam self |
@@ -1010,6 +1018,36 @@ private StructType inferLiteralType(LiteralExpr le) {
10101018 )
10111019}
10121020
1021+ private class Vec extends Struct {
1022+ Vec ( ) { this .getCanonicalPath ( ) = "alloc::vec::Vec" }
1023+
1024+ TypeParamTypeParameter getElementTypeParameter ( ) {
1025+ result .getTypeParam ( ) = this .getGenericParamList ( ) .getTypeParam ( 0 )
1026+ }
1027+ }
1028+
1029+ pragma [ nomagic]
1030+ private Type inferIndexExprType ( IndexExpr ie , TypePath path ) {
1031+ // TODO: Should be implemented as method resolution, using the special
1032+ // `std::ops::Index` trait.
1033+ exists ( TypePath exprPath , Builtins:: BuiltinType t , TypeParameter tp |
1034+ TStruct ( t ) = inferType ( ie .getIndex ( ) ) and
1035+ (
1036+ t instanceof Builtins:: I32
1037+ or
1038+ t instanceof Builtins:: Usize
1039+ ) and
1040+ result = inferType ( ie .getBase ( ) , exprPath ) and
1041+ exprPath .isCons ( tp , path )
1042+ |
1043+ tp = any ( Vec v ) .getElementTypeParameter ( )
1044+ or
1045+ tp instanceof ArrayTypeParameter
1046+ or
1047+ tp instanceof SliceTypeParameter
1048+ )
1049+ }
1050+
10131051private module MethodCall {
10141052 /** An expression that calls a method. */
10151053 abstract private class MethodCallImpl extends Expr {
@@ -1347,6 +1385,8 @@ private module Cached {
13471385 or
13481386 result = inferLiteralType ( n ) and
13491387 path .isEmpty ( )
1388+ or
1389+ result = inferIndexExprType ( n , path )
13501390 }
13511391}
13521392
@@ -1363,7 +1403,7 @@ private module Debug {
13631403 exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
13641404 result .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
13651405 filepath .matches ( "%/main.rs" ) and
1366- startline = 948
1406+ startline = 1718
13671407 )
13681408 }
13691409
0 commit comments