Skip to content

Commit f09c3c5

Browse files
committed
Rust: Handle self enum/struct uses
1 parent 3bfb4fb commit f09c3c5

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ abstract class ItemNode extends Locatable {
181181
else result = this.getImmediateParentModule().getImmediateParentModule()
182182
or
183183
name = "self" and
184-
if this instanceof Module then result = this else result = this.getImmediateParentModule()
184+
if this instanceof Module or this instanceof Enum or this instanceof Struct
185+
then result = this
186+
else result = this.getImmediateParentModule()
185187
or
186188
name = "Self" and
187189
this = result.(ImplOrTraitItemNode).getAnItemInSelfScope()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,17 +505,17 @@ mod m21 {
505505
mod m33 {
506506
#[rustfmt::skip]
507507
use super::m22::MyEnum::{ // $ item=I105
508-
self // $ MISSING: item=I105 $ SPURIOUS: item=I107
508+
self // $ item=I105
509509
};
510510

511511
#[rustfmt::skip]
512512
use super::m22::MyStruct::{ // $ item=I106
513-
self // $ MISSING: item=I106 $ SPURIOUS: item=I107
513+
self // $ item=I106
514514
};
515515

516516
fn f() {
517517
let _ = MyEnum::A; // $ MISSING: item=I104
518-
let _ = MyStruct {}; // $ MISSING: item=I106
518+
let _ = MyStruct {}; // $ item=I106
519519
}
520520
}
521521
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,13 @@ resolvePath
226226
| main.rs:507:13:507:17 | super | main.rs:496:1:521:1 | mod m21 |
227227
| main.rs:507:13:507:22 | ...::m22 | main.rs:497:5:503:5 | mod m22 |
228228
| main.rs:507:13:507:30 | ...::MyEnum | main.rs:498:9:500:9 | enum MyEnum |
229-
| main.rs:508:13:508:16 | self | main.rs:497:5:503:5 | mod m22 |
229+
| main.rs:508:13:508:16 | self | main.rs:498:9:500:9 | enum MyEnum |
230230
| main.rs:512:13:512:17 | super | main.rs:496:1:521:1 | mod m21 |
231231
| main.rs:512:13:512:22 | ...::m22 | main.rs:497:5:503:5 | mod m22 |
232232
| main.rs:512:13:512:32 | ...::MyStruct | main.rs:502:9:502:28 | struct MyStruct |
233-
| main.rs:513:13:513:16 | self | main.rs:497:5:503:5 | mod m22 |
233+
| main.rs:513:13:513:16 | self | main.rs:502:9:502:28 | struct MyStruct |
234+
| main.rs:517:21:517:26 | MyEnum | main.rs:498:9:500:9 | enum MyEnum |
235+
| main.rs:518:21:518:28 | MyStruct | main.rs:502:9:502:28 | struct MyStruct |
234236
| main.rs:524:5:524:6 | my | main.rs:1:1:1:7 | mod my |
235237
| main.rs:524:5:524:14 | ...::nested | my.rs:1:1:1:15 | mod nested |
236238
| main.rs:524:5:524:23 | ...::nested1 | my/nested.rs:1:1:17:1 | mod nested1 |

0 commit comments

Comments
 (0)