3
3
* in the code viewer.
4
4
*/
5
5
6
+ private import rust
6
7
private import codeql.rust.elements.Variable
7
8
private import codeql.rust.elements.Locatable
8
9
private import codeql.rust.elements.FormatArgsExpr
@@ -12,6 +13,7 @@ private import codeql.rust.elements.MacroCall
12
13
private import codeql.rust.elements.NamedFormatArgument
13
14
private import codeql.rust.elements.PositionalFormatArgument
14
15
private import codeql.Locations
16
+ private import codeql.rust.internal.PathResolution
15
17
16
18
/** An element with an associated definition. */
17
19
abstract class Use extends Locatable {
@@ -30,7 +32,8 @@ private module Cached {
30
32
newtype TDef =
31
33
TVariable ( Variable v ) or
32
34
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 )
34
37
35
38
/**
36
39
* Gets an element, of kind `kind`, that element `use` uses, if any.
@@ -51,7 +54,8 @@ class Definition extends Cached::TDef {
51
54
Location getLocation ( ) {
52
55
result = this .asVariable ( ) .getLocation ( ) or
53
56
result = this .asName ( ) .getLocation ( ) or
54
- result = this .asExpr ( ) .getLocation ( )
57
+ result = this .asExpr ( ) .getLocation ( ) or
58
+ result = this .asItemNode ( ) .getLocation ( )
55
59
}
56
60
57
61
/** Gets this definition as a `Variable` */
@@ -63,11 +67,15 @@ class Definition extends Cached::TDef {
63
67
/** Gets this definition as an `Expr` */
64
68
Expr asExpr ( ) { this = Cached:: TFormatArgsArgIndex ( result ) }
65
69
70
+ /** Gets this definition as an `ItemNode` */
71
+ ItemNode asItemNode ( ) { this = Cached:: TItemNode ( result ) }
72
+
66
73
/** Gets the string representation of this element. */
67
74
string toString ( ) {
68
75
result = this .asExpr ( ) .toString ( ) or
69
76
result = this .asVariable ( ) .toString ( ) or
70
- result = this .asName ( ) .getText ( )
77
+ result = this .asName ( ) .getText ( ) or
78
+ result = this .asItemNode ( ) .toString ( )
71
79
}
72
80
}
73
81
@@ -124,3 +132,20 @@ private class PositionalFormatArgumentUse extends Use instanceof PositionalForma
124
132
125
133
override string getUseType ( ) { result = "format argument" }
126
134
}
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