Skip to content

Commit 100de73

Browse files
authored
Merge pull request #18689 from hvitved/rust/path-resolution-type-param
Rust: Extend path resolution to cover type parameters
2 parents 9bcfd01 + 493953e commit 100de73

File tree

3 files changed

+72
-39
lines changed

3 files changed

+72
-39
lines changed

rust/ql/lib/codeql/rust/elements/internal/PathResolution.qll

+6
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ private class BlockExprItemNode extends ItemNode instanceof BlockExpr {
232232
override Visibility getVisibility() { none() }
233233
}
234234

235+
private class TypeParamItemNode extends ItemNode instanceof TypeParam {
236+
override string getName() { result = TypeParam.super.getName().getText() }
237+
238+
override Visibility getVisibility() { none() }
239+
}
240+
235241
/** Holds if `item` has the name `name` and is a top-level item inside `f`. */
236242
private predicate sourceFileEdge(SourceFile f, string name, ItemNode item) {
237243
item = f.getAnItem() and

rust/ql/test/library-tests/path-resolution/main.rs

+21
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,27 @@ mod m9 {
191191
} // I57
192192
}
193193

194+
mod m10 {
195+
#[rustfmt::skip]
196+
pub struct MyStruct<
197+
T // I58
198+
>
199+
{
200+
x: T, // $ item=I58
201+
} // I59
202+
203+
#[rustfmt::skip]
204+
pub fn f<T>( // I60
205+
x: T // $ item=I60
206+
) ->
207+
MyStruct<
208+
T // $ item=I60
209+
> // $ item=I59
210+
{
211+
MyStruct { x } // $ item=I59
212+
}
213+
}
214+
194215
fn main() {
195216
my::nested::nested1::nested2::f(); // $ item=I4
196217
my::f(); // $ item=I38

rust/ql/test/library-tests/path-resolution/path-resolution.expected

+45-39
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod
1212
| main.rs:122:1:137:1 | mod m7 |
1313
| main.rs:139:1:182:1 | mod m8 |
1414
| main.rs:184:1:192:1 | mod m9 |
15+
| main.rs:194:1:213:1 | mod m10 |
1516
| my2/mod.rs:1:1:1:16 | mod nested2 |
1617
| my2/nested2.rs:1:1:11:1 | mod nested3 |
1718
| my2/nested2.rs:2:5:10:5 | mod nested4 |
@@ -37,7 +38,7 @@ resolvePath
3738
| main.rs:30:17:30:21 | super | main.rs:18:5:36:5 | mod m2 |
3839
| main.rs:30:17:30:24 | ...::f | main.rs:19:9:21:9 | fn f |
3940
| main.rs:33:17:33:17 | f | main.rs:19:9:21:9 | fn f |
40-
| main.rs:40:9:40:13 | super | main.rs:1:1:212:2 | SourceFile |
41+
| main.rs:40:9:40:13 | super | main.rs:1:1:233:2 | SourceFile |
4142
| main.rs:40:9:40:17 | ...::m1 | main.rs:13:1:37:1 | mod m1 |
4243
| main.rs:40:9:40:21 | ...::m2 | main.rs:18:5:36:5 | mod m2 |
4344
| main.rs:40:9:40:24 | ...::g | main.rs:23:9:27:9 | fn g |
@@ -49,7 +50,7 @@ resolvePath
4950
| main.rs:61:17:61:19 | Foo | main.rs:59:9:59:21 | struct Foo |
5051
| main.rs:64:13:64:15 | Foo | main.rs:53:5:53:17 | struct Foo |
5152
| main.rs:66:5:66:5 | f | main.rs:55:5:62:5 | fn f |
52-
| main.rs:68:5:68:8 | self | main.rs:1:1:212:2 | SourceFile |
53+
| main.rs:68:5:68:8 | self | main.rs:1:1:233:2 | SourceFile |
5354
| main.rs:68:5:68:11 | ...::i | main.rs:71:1:83:1 | fn i |
5455
| main.rs:74:13:74:15 | Foo | main.rs:48:1:48:13 | struct Foo |
5556
| main.rs:81:17:81:19 | Foo | main.rs:77:9:79:9 | struct Foo |
@@ -63,7 +64,7 @@ resolvePath
6364
| main.rs:87:57:87:66 | ...::g | my2/nested2.rs:7:9:9:9 | fn g |
6465
| main.rs:87:80:87:86 | nested4 | my2/nested2.rs:2:5:10:5 | mod nested4 |
6566
| main.rs:100:5:100:22 | f_defined_in_macro | main.rs:99:18:99:42 | fn f_defined_in_macro |
66-
| main.rs:117:13:117:17 | super | main.rs:1:1:212:2 | SourceFile |
67+
| main.rs:117:13:117:17 | super | main.rs:1:1:233:2 | SourceFile |
6768
| main.rs:117:13:117:21 | ...::m5 | main.rs:103:1:107:1 | mod m5 |
6869
| main.rs:118:9:118:9 | f | main.rs:104:5:106:5 | fn f |
6970
| main.rs:118:9:118:9 | f | main.rs:110:5:112:5 | fn f |
@@ -93,42 +94,47 @@ resolvePath
9394
| main.rs:188:19:188:32 | ...::MyStruct | main.rs:185:5:185:26 | struct MyStruct |
9495
| main.rs:190:9:190:12 | self | main.rs:184:1:192:1 | mod m9 |
9596
| main.rs:190:9:190:22 | ...::MyStruct | main.rs:185:5:185:26 | struct MyStruct |
96-
| main.rs:195:5:195:6 | my | main.rs:1:1:1:7 | mod my |
97-
| main.rs:195:5:195:14 | ...::nested | my.rs:1:1:1:15 | mod nested |
98-
| main.rs:195:5:195:23 | ...::nested1 | my/nested.rs:1:1:17:1 | mod nested1 |
99-
| main.rs:195:5:195:32 | ...::nested2 | my/nested.rs:2:5:11:5 | mod nested2 |
100-
| main.rs:195:5:195:35 | ...::f | my/nested.rs:3:9:5:9 | fn f |
101-
| main.rs:196:5:196:6 | my | main.rs:1:1:1:7 | mod my |
102-
| main.rs:196:5:196:9 | ...::f | my.rs:5:1:7:1 | fn f |
103-
| main.rs:197:5:197:11 | nested2 | my2/mod.rs:1:1:1:16 | mod nested2 |
104-
| main.rs:197:5:197:20 | ...::nested3 | my2/nested2.rs:1:1:11:1 | mod nested3 |
105-
| main.rs:197:5:197:29 | ...::nested4 | my2/nested2.rs:2:5:10:5 | mod nested4 |
106-
| main.rs:197:5:197:32 | ...::f | my2/nested2.rs:3:9:5:9 | fn f |
107-
| main.rs:198:5:198:5 | f | my2/nested2.rs:3:9:5:9 | fn f |
108-
| main.rs:199:5:199:5 | g | my2/nested2.rs:7:9:9:9 | fn g |
109-
| main.rs:200:5:200:9 | crate | main.rs:1:1:212:2 | SourceFile |
110-
| main.rs:200:5:200:12 | ...::h | main.rs:50:1:69:1 | fn h |
111-
| main.rs:201:5:201:6 | m1 | main.rs:13:1:37:1 | mod m1 |
112-
| main.rs:201:5:201:10 | ...::m2 | main.rs:18:5:36:5 | mod m2 |
113-
| main.rs:201:5:201:13 | ...::g | main.rs:23:9:27:9 | fn g |
114-
| main.rs:202:5:202:6 | m1 | main.rs:13:1:37:1 | mod m1 |
115-
| main.rs:202:5:202:10 | ...::m2 | main.rs:18:5:36:5 | mod m2 |
116-
| main.rs:202:5:202:14 | ...::m3 | main.rs:29:9:35:9 | mod m3 |
117-
| main.rs:202:5:202:17 | ...::h | main.rs:30:27:34:13 | fn h |
118-
| main.rs:203:5:203:6 | m4 | main.rs:39:1:46:1 | mod m4 |
119-
| main.rs:203:5:203:9 | ...::i | main.rs:42:5:45:5 | fn i |
120-
| main.rs:204:5:204:5 | h | main.rs:50:1:69:1 | fn h |
121-
| main.rs:205:5:205:11 | f_alias | my2/nested2.rs:3:9:5:9 | fn f |
122-
| main.rs:206:5:206:11 | g_alias | my2/nested2.rs:7:9:9:9 | fn g |
123-
| main.rs:207:5:207:5 | j | main.rs:97:1:101:1 | fn j |
124-
| main.rs:208:5:208:6 | m6 | main.rs:109:1:120:1 | mod m6 |
125-
| main.rs:208:5:208:9 | ...::g | main.rs:114:5:119:5 | fn g |
126-
| main.rs:209:5:209:6 | m7 | main.rs:122:1:137:1 | mod m7 |
127-
| main.rs:209:5:209:9 | ...::f | main.rs:129:5:136:5 | fn f |
128-
| main.rs:210:5:210:6 | m8 | main.rs:139:1:182:1 | mod m8 |
129-
| main.rs:210:5:210:9 | ...::g | main.rs:169:5:181:5 | fn g |
130-
| main.rs:211:5:211:6 | m9 | main.rs:184:1:192:1 | mod m9 |
131-
| main.rs:211:5:211:9 | ...::f | main.rs:187:5:191:5 | fn f |
97+
| main.rs:200:12:200:12 | T | main.rs:197:7:197:7 | TypeParam |
98+
| main.rs:205:12:205:12 | T | main.rs:204:14:204:14 | TypeParam |
99+
| main.rs:207:7:209:7 | MyStruct::<...> | main.rs:195:5:201:5 | struct MyStruct |
100+
| main.rs:208:9:208:9 | T | main.rs:204:14:204:14 | TypeParam |
101+
| main.rs:211:9:211:16 | MyStruct | main.rs:195:5:201:5 | struct MyStruct |
102+
| main.rs:216:5:216:6 | my | main.rs:1:1:1:7 | mod my |
103+
| main.rs:216:5:216:14 | ...::nested | my.rs:1:1:1:15 | mod nested |
104+
| main.rs:216:5:216:23 | ...::nested1 | my/nested.rs:1:1:17:1 | mod nested1 |
105+
| main.rs:216:5:216:32 | ...::nested2 | my/nested.rs:2:5:11:5 | mod nested2 |
106+
| main.rs:216:5:216:35 | ...::f | my/nested.rs:3:9:5:9 | fn f |
107+
| main.rs:217:5:217:6 | my | main.rs:1:1:1:7 | mod my |
108+
| main.rs:217:5:217:9 | ...::f | my.rs:5:1:7:1 | fn f |
109+
| main.rs:218:5:218:11 | nested2 | my2/mod.rs:1:1:1:16 | mod nested2 |
110+
| main.rs:218:5:218:20 | ...::nested3 | my2/nested2.rs:1:1:11:1 | mod nested3 |
111+
| main.rs:218:5:218:29 | ...::nested4 | my2/nested2.rs:2:5:10:5 | mod nested4 |
112+
| main.rs:218:5:218:32 | ...::f | my2/nested2.rs:3:9:5:9 | fn f |
113+
| main.rs:219:5:219:5 | f | my2/nested2.rs:3:9:5:9 | fn f |
114+
| main.rs:220:5:220:5 | g | my2/nested2.rs:7:9:9:9 | fn g |
115+
| main.rs:221:5:221:9 | crate | main.rs:1:1:233:2 | SourceFile |
116+
| main.rs:221:5:221:12 | ...::h | main.rs:50:1:69:1 | fn h |
117+
| main.rs:222:5:222:6 | m1 | main.rs:13:1:37:1 | mod m1 |
118+
| main.rs:222:5:222:10 | ...::m2 | main.rs:18:5:36:5 | mod m2 |
119+
| main.rs:222:5:222:13 | ...::g | main.rs:23:9:27:9 | fn g |
120+
| main.rs:223:5:223:6 | m1 | main.rs:13:1:37:1 | mod m1 |
121+
| main.rs:223:5:223:10 | ...::m2 | main.rs:18:5:36:5 | mod m2 |
122+
| main.rs:223:5:223:14 | ...::m3 | main.rs:29:9:35:9 | mod m3 |
123+
| main.rs:223:5:223:17 | ...::h | main.rs:30:27:34:13 | fn h |
124+
| main.rs:224:5:224:6 | m4 | main.rs:39:1:46:1 | mod m4 |
125+
| main.rs:224:5:224:9 | ...::i | main.rs:42:5:45:5 | fn i |
126+
| main.rs:225:5:225:5 | h | main.rs:50:1:69:1 | fn h |
127+
| main.rs:226:5:226:11 | f_alias | my2/nested2.rs:3:9:5:9 | fn f |
128+
| main.rs:227:5:227:11 | g_alias | my2/nested2.rs:7:9:9:9 | fn g |
129+
| main.rs:228:5:228:5 | j | main.rs:97:1:101:1 | fn j |
130+
| main.rs:229:5:229:6 | m6 | main.rs:109:1:120:1 | mod m6 |
131+
| main.rs:229:5:229:9 | ...::g | main.rs:114:5:119:5 | fn g |
132+
| main.rs:230:5:230:6 | m7 | main.rs:122:1:137:1 | mod m7 |
133+
| main.rs:230:5:230:9 | ...::f | main.rs:129:5:136:5 | fn f |
134+
| main.rs:231:5:231:6 | m8 | main.rs:139:1:182:1 | mod m8 |
135+
| main.rs:231:5:231:9 | ...::g | main.rs:169:5:181:5 | fn g |
136+
| main.rs:232:5:232:6 | m9 | main.rs:184:1:192:1 | mod m9 |
137+
| main.rs:232:5:232:9 | ...::f | main.rs:187:5:191:5 | fn f |
132138
| my2/mod.rs:5:5:5:11 | nested2 | my2/mod.rs:1:1:1:16 | mod nested2 |
133139
| my2/mod.rs:5:5:5:20 | ...::nested3 | my2/nested2.rs:1:1:11:1 | mod nested3 |
134140
| my2/mod.rs:5:5:5:29 | ...::nested4 | my2/nested2.rs:2:5:10:5 | mod nested4 |

0 commit comments

Comments
 (0)