Skip to content

Commit 98a02d8

Browse files
committed
Rust: Account for attribute expansions in path resolution
1 parent aab0279 commit 98a02d8

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

@@ -648,11 +653,7 @@ final class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
648653

649654
override Visibility getVisibility() { result = Impl.super.getVisibility() }
650655

651-
TypeParamItemNode getBlanketImplementationTypeParam() {
652-
result = this.resolveSelfTy() and
653-
// This impl block is not superseded by the expansion of an attribute macro.
654-
not exists(super.getAttributeMacroExpansion())
655-
}
656+
TypeParamItemNode getBlanketImplementationTypeParam() { result = this.resolveSelfTy() }
656657

657658
/**
658659
* 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
@@ -792,8 +792,7 @@ fn main() {
792792
m23::f(); // $ item=I108
793793
m24::f(); // $ item=I121
794794
zelf::h(); // $ item=I25
795-
z_changed(); // $ MISSING: item=I122
796-
AStruct::z_on_type(); // $ MISSING: item=I124
797-
AStruct {} // $ item=I123
798-
.z_on_instance(); // MISSING: item=I125
795+
z_changed(); // $ item=I122
796+
AStruct::z_on_type(); // $ item=I124
797+
AStruct {}.z_on_instance(); // $ item=I123 item=I125
799798
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ resolvePath
6464
| main.rs:30:17:30:21 | super | main.rs:18:5:36:5 | mod m2 |
6565
| main.rs:30:17:30:24 | ...::f | main.rs:19:9:21:9 | fn f |
6666
| main.rs:33:17:33:17 | f | main.rs:19:9:21:9 | fn f |
67-
| main.rs:40:9:40:13 | super | main.rs:1:1:799:2 | SourceFile |
67+
| main.rs:40:9:40:13 | super | main.rs:1:1:798:2 | SourceFile |
6868
| main.rs:40:9:40:17 | ...::m1 | main.rs:13:1:37:1 | mod m1 |
6969
| main.rs:40:9:40:21 | ...::m2 | main.rs:18:5:36:5 | mod m2 |
7070
| main.rs:40:9:40:24 | ...::g | main.rs:23:9:27:9 | fn g |
@@ -76,7 +76,7 @@ resolvePath
7676
| main.rs:61:17:61:19 | Foo | main.rs:59:9:59:21 | struct Foo |
7777
| main.rs:64:13:64:15 | Foo | main.rs:53:5:53:17 | struct Foo |
7878
| main.rs:66:5:66:5 | f | main.rs:55:5:62:5 | fn f |
79-
| main.rs:68:5:68:8 | self | main.rs:1:1:799:2 | SourceFile |
79+
| main.rs:68:5:68:8 | self | main.rs:1:1:798:2 | SourceFile |
8080
| main.rs:68:5:68:11 | ...::i | main.rs:71:1:83:1 | fn i |
8181
| main.rs:74:13:74:15 | Foo | main.rs:48:1:48:13 | struct Foo |
8282
| main.rs:78:16:78:18 | i32 | {EXTERNAL LOCATION} | struct i32 |
@@ -91,7 +91,7 @@ resolvePath
9191
| main.rs:87:57:87:66 | ...::g | my2/nested2.rs:7:9:9:9 | fn g |
9292
| main.rs:87:80:87:86 | nested4 | my2/nested2.rs:2:5:10:5 | mod nested4 |
9393
| main.rs:100:5:100:22 | f_defined_in_macro | main.rs:99:18:99:42 | fn f_defined_in_macro |
94-
| main.rs:117:13:117:17 | super | main.rs:1:1:799:2 | SourceFile |
94+
| main.rs:117:13:117:17 | super | main.rs:1:1:798:2 | SourceFile |
9595
| main.rs:117:13:117:21 | ...::m5 | main.rs:103:1:107:1 | mod m5 |
9696
| main.rs:118:9:118:9 | f | main.rs:104:5:106:5 | fn f |
9797
| main.rs:118:9:118:9 | f | main.rs:110:5:112:5 | fn f |
@@ -410,7 +410,9 @@ resolvePath
410410
| main.rs:793:5:793:10 | ...::f | main.rs:675:5:688:5 | fn f |
411411
| main.rs:794:5:794:8 | zelf | main.rs:0:0:0:0 | Crate(main@0.0.1) |
412412
| main.rs:794:5:794:11 | ...::h | main.rs:50:1:69:1 | fn h |
413+
| main.rs:795:5:795:13 | z_changed | main.rs:694:1:694:8 | fn z_changed |
413414
| main.rs:796:5:796:11 | AStruct | main.rs:696:1:696:17 | struct AStruct |
415+
| main.rs:796:5:796:22 | ...::z_on_type | main.rs:700:5:700:16 | fn z_on_type |
414416
| main.rs:797:5:797:11 | AStruct | main.rs:696:1:696:17 | struct AStruct |
415417
| my2/mod.rs:5:5:5:11 | nested2 | my2/mod.rs:1:1:1:16 | mod nested2 |
416418
| my2/mod.rs:5:5:5:20 | ...::nested3 | my2/nested2.rs:1:1:11:1 | mod nested3 |
@@ -427,7 +429,7 @@ resolvePath
427429
| my2/my3/mod.rs:3:5:3:5 | g | my2/mod.rs:3:1:6:1 | fn g |
428430
| my2/my3/mod.rs:4:5:4:5 | h | main.rs:50:1:69:1 | fn h |
429431
| my2/my3/mod.rs:7:5:7:9 | super | my2/mod.rs:1:1:17:30 | SourceFile |
430-
| my2/my3/mod.rs:7:5:7:16 | ...::super | main.rs:1:1:799:2 | SourceFile |
432+
| my2/my3/mod.rs:7:5:7:16 | ...::super | main.rs:1:1:798:2 | SourceFile |
431433
| my2/my3/mod.rs:7:5:7:19 | ...::h | main.rs:50:1:69:1 | fn h |
432434
| my2/my3/mod.rs:8:5:8:9 | super | my2/mod.rs:1:1:17:30 | SourceFile |
433435
| my2/my3/mod.rs:8:5:8:12 | ...::g | my2/mod.rs:3:1:6:1 | fn g |

0 commit comments

Comments
 (0)