33 * in the code viewer.
44 */
55
6+ private import rust
67private import codeql.rust.elements.Variable
78private import codeql.rust.elements.Locatable
89private import codeql.rust.elements.FormatArgsExpr
@@ -12,6 +13,7 @@ private import codeql.rust.elements.MacroCall
1213private import codeql.rust.elements.NamedFormatArgument
1314private import codeql.rust.elements.PositionalFormatArgument
1415private import codeql.Locations
16+ private import codeql.rust.internal.PathResolution
1517
1618/** An element with an associated definition. */
1719abstract class Use extends Locatable {
@@ -30,7 +32,8 @@ private module Cached {
3032 newtype TDef =
3133 TVariable ( Variable v ) or
3234 TFormatArgsArgName ( Name name ) { name = any ( FormatArgsArg a ) .getName ( ) } or
33- TFormatArgsArgIndex ( Expr e ) { e = any ( FormatArgsArg a ) .getExpr ( ) }
35+ TFormatArgsArgIndex ( Expr e ) { e = any ( FormatArgsArg a ) .getExpr ( ) } or
36+ TItemNode ( ItemNode i )
3437
3538 /**
3639 * Gets an element, of kind `kind`, that element `use` uses, if any.
@@ -51,7 +54,8 @@ class Definition extends Cached::TDef {
5154 Location getLocation ( ) {
5255 result = this .asVariable ( ) .getLocation ( ) or
5356 result = this .asName ( ) .getLocation ( ) or
54- result = this .asExpr ( ) .getLocation ( )
57+ result = this .asExpr ( ) .getLocation ( ) or
58+ result = this .asItemNode ( ) .getLocation ( )
5559 }
5660
5761 /** Gets this definition as a `Variable` */
@@ -63,11 +67,15 @@ class Definition extends Cached::TDef {
6367 /** Gets this definition as an `Expr` */
6468 Expr asExpr ( ) { this = Cached:: TFormatArgsArgIndex ( result ) }
6569
70+ /** Gets this definition as an `ItemNode` */
71+ ItemNode asItemNode ( ) { this = Cached:: TItemNode ( result ) }
72+
6673 /** Gets the string representation of this element. */
6774 string toString ( ) {
6875 result = this .asExpr ( ) .toString ( ) or
6976 result = this .asVariable ( ) .toString ( ) or
70- result = this .asName ( ) .getText ( )
77+ result = this .asName ( ) .getText ( ) or
78+ result = this .asItemNode ( ) .toString ( )
7179 }
7280}
7381
@@ -124,3 +132,20 @@ private class PositionalFormatArgumentUse extends Use instanceof PositionalForma
124132
125133 override string getUseType ( ) { result = "format argument" }
126134}
135+
136+ private class PathUse extends Use instanceof Path {
137+ override Definition getDefinition ( ) { result .asItemNode ( ) = resolvePath ( this ) }
138+
139+ override string getUseType ( ) { result = "path" }
140+ }
141+
142+ private class FileUse extends Use instanceof Name {
143+ override Definition getDefinition ( ) {
144+ exists ( Module m |
145+ this = m .getName ( ) and
146+ fileImport ( m , result .asItemNode ( ) )
147+ )
148+ }
149+
150+ override string getUseType ( ) { result = "file" }
151+ }
0 commit comments