File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
rust/ql/lib/codeql/rust/internal Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -1010,6 +1010,24 @@ private StructType inferLiteralType(LiteralExpr le) {
10101010 )
10111011}
10121012
1013+ private class Vec extends Struct {
1014+ Vec ( ) { this .getCanonicalPath ( ) = "alloc::vec::Vec" }
1015+
1016+ TypeParamTypeParameter getElementTypeParameter ( ) {
1017+ result .getTypeParam ( ) = this .getGenericParamList ( ) .getTypeParam ( 0 )
1018+ }
1019+ }
1020+
1021+ pragma [ nomagic]
1022+ private Type inferIndexExprType ( IndexExpr ie , TypePath path ) {
1023+ // TODO: Should be implemented as method resolution, using the special
1024+ // `std::ops::Index` trait.
1025+ exists ( TypePath exprPath |
1026+ result = inferType ( ie .getBase ( ) , exprPath ) and
1027+ exprPath .isCons ( any ( Vec v ) .getElementTypeParameter ( ) , path )
1028+ )
1029+ }
1030+
10131031private module MethodCall {
10141032 /** An expression that calls a method. */
10151033 abstract private class MethodCallImpl extends Expr {
@@ -1347,6 +1365,8 @@ private module Cached {
13471365 or
13481366 result = inferLiteralType ( n ) and
13491367 path .isEmpty ( )
1368+ or
1369+ result = inferIndexExprType ( n , path )
13501370 }
13511371}
13521372
You can’t perform that action at this time.
0 commit comments