Skip to content

Commit 32365fd

Browse files
committed
Rust: Account for attribute expansions in path resolution
1 parent c7a9cc5 commit 32365fd

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ private ItemNode getAChildSuccessor(ItemNode item, string name, SuccessorKind ki
156156
* - https://doc.rust-lang.org/reference/names/namespaces.html
157157
*/
158158
abstract class ItemNode extends Locatable {
159+
ItemNode() {
160+
// Exclude items that are superceded by the expansion of an attribute macro.
161+
not this.(Item).hasAttributeMacroExpansion()
162+
}
163+
159164
/** Gets the (original) name of this item. */
160165
abstract string getName();
161166

@@ -660,11 +665,7 @@ final class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
660665

661666
override Visibility getVisibility() { result = Impl.super.getVisibility() }
662667

663-
TypeParamItemNode getBlanketImplementationTypeParam() {
664-
result = this.resolveSelfTy() and
665-
// This impl block is not superseded by the expansion of an attribute macro.
666-
not exists(super.getAttributeMacroExpansion())
667-
}
668+
TypeParamItemNode getBlanketImplementationTypeParam() { result = this.resolveSelfTy() }
668669

669670
/**
670671
* Holds if this impl block is a blanket implementation. That is, the

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,7 @@ fn main() {
798798
m23::f(); // $ item=I108
799799
m24::f(); // $ item=I121
800800
zelf::h(); // $ item=I25
801-
z_changed(); // $ MISSING: item=I122
802-
AStruct::z_on_type(); // $ MISSING: item=I124
803-
AStruct {} // $ item=I123
804-
.z_on_instance(); // MISSING: item=I125
801+
z_changed(); // $ item=I122
802+
AStruct::z_on_type(); // $ item=I124
803+
AStruct {}.z_on_instance(); // $ item=I123 item=I125
805804
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ resolvePath
6666
| main.rs:36:17:36:21 | super | main.rs:24:5:42:5 | mod m2 |
6767
| main.rs:36:17:36:24 | ...::f | main.rs:25:9:27:9 | fn f |
6868
| main.rs:39:17:39:17 | f | main.rs:25:9:27:9 | fn f |
69-
| main.rs:46:9:46:13 | super | main.rs:1:1:805:2 | SourceFile |
69+
| main.rs:46:9:46:13 | super | main.rs:1:1:804:2 | SourceFile |
7070
| main.rs:46:9:46:17 | ...::m1 | main.rs:19:1:43:1 | mod m1 |
7171
| main.rs:46:9:46:21 | ...::m2 | main.rs:24:5:42:5 | mod m2 |
7272
| main.rs:46:9:46:24 | ...::g | main.rs:29:9:33:9 | fn g |
@@ -78,7 +78,7 @@ resolvePath
7878
| main.rs:67:17:67:19 | Foo | main.rs:65:9:65:21 | struct Foo |
7979
| main.rs:70:13:70:15 | Foo | main.rs:59:5:59:17 | struct Foo |
8080
| main.rs:72:5:72:5 | f | main.rs:61:5:68:5 | fn f |
81-
| main.rs:74:5:74:8 | self | main.rs:1:1:805:2 | SourceFile |
81+
| main.rs:74:5:74:8 | self | main.rs:1:1:804:2 | SourceFile |
8282
| main.rs:74:5:74:11 | ...::i | main.rs:77:1:89:1 | fn i |
8383
| main.rs:80:13:80:15 | Foo | main.rs:54:1:54:13 | struct Foo |
8484
| main.rs:84:16:84:18 | i32 | {EXTERNAL LOCATION} | struct i32 |
@@ -93,7 +93,7 @@ resolvePath
9393
| main.rs:93:57:93:66 | ...::g | my2/nested2.rs:7:9:9:9 | fn g |
9494
| main.rs:93:80:93:86 | nested4 | my2/nested2.rs:2:5:10:5 | mod nested4 |
9595
| main.rs:106:5:106:22 | f_defined_in_macro | main.rs:105:18:105:42 | fn f_defined_in_macro |
96-
| main.rs:123:13:123:17 | super | main.rs:1:1:805:2 | SourceFile |
96+
| main.rs:123:13:123:17 | super | main.rs:1:1:804:2 | SourceFile |
9797
| main.rs:123:13:123:21 | ...::m5 | main.rs:109:1:113:1 | mod m5 |
9898
| main.rs:124:9:124:9 | f | main.rs:110:5:112:5 | fn f |
9999
| main.rs:124:9:124:9 | f | main.rs:116:5:118:5 | fn f |
@@ -412,7 +412,9 @@ resolvePath
412412
| main.rs:799:5:799:10 | ...::f | main.rs:681:5:694:5 | fn f |
413413
| main.rs:800:5:800:8 | zelf | main.rs:0:0:0:0 | Crate(main@0.0.1) |
414414
| main.rs:800:5:800:11 | ...::h | main.rs:56:1:75:1 | fn h |
415+
| main.rs:801:5:801:13 | z_changed | main.rs:700:1:700:8 | fn z_changed |
415416
| main.rs:802:5:802:11 | AStruct | main.rs:702:1:702:17 | struct AStruct |
417+
| main.rs:802:5:802:22 | ...::z_on_type | main.rs:706:5:706:16 | fn z_on_type |
416418
| main.rs:803:5:803:11 | AStruct | main.rs:702:1:702:17 | struct AStruct |
417419
| my2/mod.rs:5:5:5:11 | nested2 | my2/mod.rs:1:1:1:16 | mod nested2 |
418420
| my2/mod.rs:5:5:5:20 | ...::nested3 | my2/nested2.rs:1:1:11:1 | mod nested3 |
@@ -434,7 +436,7 @@ resolvePath
434436
| my2/my3/mod.rs:3:5:3:5 | g | my2/mod.rs:3:1:6:1 | fn g |
435437
| my2/my3/mod.rs:4:5:4:5 | h | main.rs:56:1:75:1 | fn h |
436438
| my2/my3/mod.rs:7:5:7:9 | super | my2/mod.rs:1:1:23:34 | SourceFile |
437-
| my2/my3/mod.rs:7:5:7:16 | ...::super | main.rs:1:1:805:2 | SourceFile |
439+
| my2/my3/mod.rs:7:5:7:16 | ...::super | main.rs:1:1:804:2 | SourceFile |
438440
| my2/my3/mod.rs:7:5:7:19 | ...::h | main.rs:56:1:75:1 | fn h |
439441
| my2/my3/mod.rs:8:5:8:9 | super | my2/mod.rs:1:1:23:34 | SourceFile |
440442
| my2/my3/mod.rs:8:5:8:12 | ...::g | my2/mod.rs:3:1:6:1 | fn g |

0 commit comments

Comments
 (0)