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,9 +13,12 @@ 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 {
20+ Use ( ) { not this .( AstNode ) .isFromMacroExpansion ( ) }
21+
1822 /** Gets the definition associated with this element. */
1923 abstract Definition getDefinition ( ) ;
2024
@@ -30,7 +34,8 @@ private module Cached {
3034 newtype TDef =
3135 TVariable ( Variable v ) or
3236 TFormatArgsArgName ( Name name ) { name = any ( FormatArgsArg a ) .getName ( ) } or
33- TFormatArgsArgIndex ( Expr e ) { e = any ( FormatArgsArg a ) .getExpr ( ) }
37+ TFormatArgsArgIndex ( Expr e ) { e = any ( FormatArgsArg a ) .getExpr ( ) } or
38+ TItemNode ( ItemNode i )
3439
3540 /**
3641 * Gets an element, of kind `kind`, that element `use` uses, if any.
@@ -51,7 +56,8 @@ class Definition extends Cached::TDef {
5156 Location getLocation ( ) {
5257 result = this .asVariable ( ) .getLocation ( ) or
5358 result = this .asName ( ) .getLocation ( ) or
54- result = this .asExpr ( ) .getLocation ( )
59+ result = this .asExpr ( ) .getLocation ( ) or
60+ result = this .asItemNode ( ) .getLocation ( )
5561 }
5662
5763 /** Gets this definition as a `Variable` */
@@ -63,11 +69,15 @@ class Definition extends Cached::TDef {
6369 /** Gets this definition as an `Expr` */
6470 Expr asExpr ( ) { this = Cached:: TFormatArgsArgIndex ( result ) }
6571
72+ /** Gets this definition as an `ItemNode` */
73+ ItemNode asItemNode ( ) { this = Cached:: TItemNode ( result ) }
74+
6675 /** Gets the string representation of this element. */
6776 string toString ( ) {
6877 result = this .asExpr ( ) .toString ( ) or
6978 result = this .asVariable ( ) .toString ( ) or
70- result = this .asName ( ) .getText ( )
79+ result = this .asName ( ) .getText ( ) or
80+ result = this .asItemNode ( ) .toString ( )
7181 }
7282}
7383
@@ -124,3 +134,20 @@ private class PositionalFormatArgumentUse extends Use instanceof PositionalForma
124134
125135 override string getUseType ( ) { result = "format argument" }
126136}
137+
138+ private class PathUse extends Use instanceof Path {
139+ override Definition getDefinition ( ) { result .asItemNode ( ) = resolvePath ( this ) }
140+
141+ override string getUseType ( ) { result = "path" }
142+ }
143+
144+ private class FileUse extends Use instanceof Name {
145+ override Definition getDefinition ( ) {
146+ exists ( Module m |
147+ this = m .getName ( ) and
148+ fileImport ( m , result .asItemNode ( ) )
149+ )
150+ }
151+
152+ override string getUseType ( ) { result = "file" }
153+ }
0 commit comments