Skip to content

Commit 519e56f

Browse files
committed
Rust: Path resolution for crate::{self as foo}
1 parent 77a92c0 commit 519e56f

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ abstract class ItemNode extends Locatable {
205205
else result = this.getImmediateParentModule().getImmediateParentModule()
206206
or
207207
name = "self" and
208-
if this instanceof Module or this instanceof Enum or this instanceof Struct
208+
if
209+
this instanceof Module or
210+
this instanceof Enum or
211+
this instanceof Struct or
212+
this instanceof Crate
209213
then result = this
210214
else result = this.getImmediateParentModule()
211215
or

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ impl AStruct // $ item=I123
638638

639639
use std::{self as ztd}; // $ item=std
640640

641-
fn use_ztd(x: ztd::string::String) {} // $ MISSING: item=String
641+
fn use_ztd(x: ztd::string::String) {} // $ item=String
642642

643643
fn main() {
644644
my::nested::nested1::nested2::f(); // $ item=I4

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ resolvePath
277277
| main.rs:635:7:635:16 | proc_macro | proc_macro.rs:0:0:0:0 | Crate([email protected]) |
278278
| main.rs:635:7:635:28 | ...::add_suffix | proc_macro.rs:4:1:12:1 | fn add_suffix |
279279
| main.rs:639:5:639:7 | std | {EXTERNAL LOCATION} | Crate([email protected]) |
280+
| main.rs:639:11:639:14 | self | {EXTERNAL LOCATION} | Crate([email protected]) |
281+
| main.rs:641:15:641:17 | ztd | {EXTERNAL LOCATION} | Crate([email protected]) |
282+
| main.rs:641:15:641:25 | ...::string | {EXTERNAL LOCATION} | mod string |
283+
| main.rs:641:15:641:33 | ...::String | {EXTERNAL LOCATION} | struct String |
280284
| main.rs:644:5:644:6 | my | main.rs:1:1:1:7 | mod my |
281285
| main.rs:644:5:644:14 | ...::nested | my.rs:1:1:1:15 | mod nested |
282286
| main.rs:644:5:644:23 | ...::nested1 | my/nested.rs:1:1:17:1 | mod nested1 |

0 commit comments

Comments
 (0)