1
1
private import rust
2
2
private import codeql.rust.elements.internal.generated.ParentChild
3
- private import codeql.rust.elements.internal.PathExprImpl :: Impl as PathExprImpl
3
+ private import codeql.rust.elements.internal.ExprImpl :: Impl as ExprImpl
4
4
private import codeql.util.DenseRank
5
5
6
6
module Impl {
@@ -138,12 +138,12 @@ module Impl {
138
138
}
139
139
140
140
/** A path expression that may access a local variable. */
141
- private class VariableAccessCand extends PathExpr {
141
+ private class VariableAccessCand extends TVariableAccess {
142
142
string name_ ;
143
143
144
144
VariableAccessCand ( ) {
145
145
exists ( Path p , PathSegment ps |
146
- p = this .getPath ( ) and
146
+ p = this .( PathExpr ) . getPath ( ) and
147
147
not p .hasQualifier ( ) and
148
148
ps = p .getPart ( ) and
149
149
not ps .hasGenericArgList ( ) and
@@ -152,9 +152,23 @@ module Impl {
152
152
not ps .hasReturnTypeSyntax ( ) and
153
153
name_ = ps .getNameRef ( ) .getText ( )
154
154
)
155
+ or
156
+ this .( ImplicitVariableAccess ) .getName ( ) = name_
155
157
}
156
158
159
+ string toString ( ) { result = name_ }
160
+
157
161
string getName ( ) { result = name_ }
162
+
163
+ predicate hasLocationInfo (
164
+ string filepath , int startline , int startcolumn , int endline , int endcolumn
165
+ ) {
166
+ this .( PathExpr )
167
+ .getLocation ( )
168
+ .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) or
169
+ this .( ImplicitVariableAccess )
170
+ .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
171
+ }
158
172
}
159
173
160
174
private AstNode getAnAncestorInVariableScope ( AstNode n ) {
@@ -164,7 +178,10 @@ module Impl {
164
178
n instanceof LetStmt or
165
179
n instanceof VariableScope
166
180
) and
167
- exists ( AstNode n0 | result = getImmediateParent ( n0 ) |
181
+ exists ( AstNode n0 |
182
+ result = getImmediateParent ( n0 ) or
183
+ result = n0 .( ImplicitVariableAccess ) .getArgument ( ) .getParent ( ) .getParent ( )
184
+ |
168
185
n0 = n
169
186
or
170
187
n0 = getAnAncestorInVariableScope ( n ) and
@@ -272,7 +289,7 @@ module Impl {
272
289
) {
273
290
name = cand .getName ( ) and
274
291
scope = [ cand .( VariableScope ) , getEnclosingScope ( cand ) ] and
275
- cand .getLocation ( ) . hasLocationInfo ( _, startline , startcolumn , endline , endcolumn ) and
292
+ cand .hasLocationInfo ( _, startline , startcolumn , endline , endcolumn ) and
276
293
nestLevel = 0
277
294
or
278
295
exists ( VariableScope inner |
@@ -347,8 +364,14 @@ module Impl {
347
364
result = this .asVariable ( ) .toString ( ) or result = this .asVariableAccessCand ( ) .toString ( )
348
365
}
349
366
350
- Location getLocation ( ) {
351
- result = this .asVariable ( ) .getLocation ( ) or result = this .asVariableAccessCand ( ) .getLocation ( )
367
+ predicate hasLocationInfo (
368
+ string filepath , int startline , int startcolumn , int endline , int endcolumn
369
+ ) {
370
+ this .asVariable ( )
371
+ .getLocation ( )
372
+ .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) or
373
+ this .asVariableAccessCand ( )
374
+ .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
352
375
}
353
376
354
377
pragma [ nomagic]
@@ -421,8 +444,12 @@ module Impl {
421
444
)
422
445
}
423
446
447
+ private import codeql.rust.elements.internal.generated.Synth
448
+
449
+ private class TVariableAccess = Synth:: TPathExpr or Synth:: TImplicitVariableAccess ;
450
+
424
451
/** A variable access. */
425
- class VariableAccess extends PathExprImpl :: PathExpr instanceof VariableAccessCand {
452
+ class VariableAccess extends ExprImpl :: Expr , TVariableAccess instanceof VariableAccessCand {
426
453
private string name ;
427
454
private Variable v ;
428
455
0 commit comments