Rust: Account for attribute expansions in path resolution

This commit is contained in:
Simon Friis Vindum
2025-09-17 15:15:29 +02:00
parent c7a9cc5a42
commit 32365fd673
3 changed files with 15 additions and 13 deletions

View File

@@ -156,6 +156,11 @@ private ItemNode getAChildSuccessor(ItemNode item, string name, SuccessorKind ki
* - https://doc.rust-lang.org/reference/names/namespaces.html
*/
abstract class ItemNode extends Locatable {
ItemNode() {
// Exclude items that are superceded by the expansion of an attribute macro.
not this.(Item).hasAttributeMacroExpansion()
}
/** Gets the (original) name of this item. */
abstract string getName();
@@ -660,11 +665,7 @@ final class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
override Visibility getVisibility() { result = Impl.super.getVisibility() }
TypeParamItemNode getBlanketImplementationTypeParam() {
result = this.resolveSelfTy() and
// This impl block is not superseded by the expansion of an attribute macro.
not exists(super.getAttributeMacroExpansion())
}
TypeParamItemNode getBlanketImplementationTypeParam() { result = this.resolveSelfTy() }
/**
* Holds if this impl block is a blanket implementation. That is, the

View File

@@ -798,8 +798,7 @@ fn main() {
m23::f(); // $ item=I108
m24::f(); // $ item=I121
zelf::h(); // $ item=I25
z_changed(); // $ MISSING: item=I122
AStruct::z_on_type(); // $ MISSING: item=I124
AStruct {} // $ item=I123
.z_on_instance(); // MISSING: item=I125
z_changed(); // $ item=I122
AStruct::z_on_type(); // $ item=I124
AStruct {}.z_on_instance(); // $ item=I123 item=I125
}

View File

@@ -66,7 +66,7 @@ resolvePath
| main.rs:36:17:36:21 | super | main.rs:24:5:42:5 | mod m2 |
| main.rs:36:17:36:24 | ...::f | main.rs:25:9:27:9 | fn f |
| main.rs:39:17:39:17 | f | main.rs:25:9:27:9 | fn f |
| main.rs:46:9:46:13 | super | main.rs:1:1:805:2 | SourceFile |
| main.rs:46:9:46:13 | super | main.rs:1:1:804:2 | SourceFile |
| main.rs:46:9:46:17 | ...::m1 | main.rs:19:1:43:1 | mod m1 |
| main.rs:46:9:46:21 | ...::m2 | main.rs:24:5:42:5 | mod m2 |
| main.rs:46:9:46:24 | ...::g | main.rs:29:9:33:9 | fn g |
@@ -78,7 +78,7 @@ resolvePath
| main.rs:67:17:67:19 | Foo | main.rs:65:9:65:21 | struct Foo |
| main.rs:70:13:70:15 | Foo | main.rs:59:5:59:17 | struct Foo |
| main.rs:72:5:72:5 | f | main.rs:61:5:68:5 | fn f |
| main.rs:74:5:74:8 | self | main.rs:1:1:805:2 | SourceFile |
| main.rs:74:5:74:8 | self | main.rs:1:1:804:2 | SourceFile |
| main.rs:74:5:74:11 | ...::i | main.rs:77:1:89:1 | fn i |
| main.rs:80:13:80:15 | Foo | main.rs:54:1:54:13 | struct Foo |
| main.rs:84:16:84:18 | i32 | {EXTERNAL LOCATION} | struct i32 |
@@ -93,7 +93,7 @@ resolvePath
| main.rs:93:57:93:66 | ...::g | my2/nested2.rs:7:9:9:9 | fn g |
| main.rs:93:80:93:86 | nested4 | my2/nested2.rs:2:5:10:5 | mod nested4 |
| main.rs:106:5:106:22 | f_defined_in_macro | main.rs:105:18:105:42 | fn f_defined_in_macro |
| main.rs:123:13:123:17 | super | main.rs:1:1:805:2 | SourceFile |
| main.rs:123:13:123:17 | super | main.rs:1:1:804:2 | SourceFile |
| main.rs:123:13:123:21 | ...::m5 | main.rs:109:1:113:1 | mod m5 |
| main.rs:124:9:124:9 | f | main.rs:110:5:112:5 | fn f |
| main.rs:124:9:124:9 | f | main.rs:116:5:118:5 | fn f |
@@ -412,7 +412,9 @@ resolvePath
| main.rs:799:5:799:10 | ...::f | main.rs:681:5:694:5 | fn f |
| main.rs:800:5:800:8 | zelf | main.rs:0:0:0:0 | Crate(main@0.0.1) |
| main.rs:800:5:800:11 | ...::h | main.rs:56:1:75:1 | fn h |
| main.rs:801:5:801:13 | z_changed | main.rs:700:1:700:8 | fn z_changed |
| main.rs:802:5:802:11 | AStruct | main.rs:702:1:702:17 | struct AStruct |
| main.rs:802:5:802:22 | ...::z_on_type | main.rs:706:5:706:16 | fn z_on_type |
| main.rs:803:5:803:11 | AStruct | main.rs:702:1:702:17 | struct AStruct |
| my2/mod.rs:5:5:5:11 | nested2 | my2/mod.rs:1:1:1:16 | mod nested2 |
| my2/mod.rs:5:5:5:20 | ...::nested3 | my2/nested2.rs:1:1:11:1 | mod nested3 |
@@ -434,7 +436,7 @@ resolvePath
| my2/my3/mod.rs:3:5:3:5 | g | my2/mod.rs:3:1:6:1 | fn g |
| my2/my3/mod.rs:4:5:4:5 | h | main.rs:56:1:75:1 | fn h |
| my2/my3/mod.rs:7:5:7:9 | super | my2/mod.rs:1:1:23:34 | SourceFile |
| my2/my3/mod.rs:7:5:7:16 | ...::super | main.rs:1:1:805:2 | SourceFile |
| my2/my3/mod.rs:7:5:7:16 | ...::super | main.rs:1:1:804:2 | SourceFile |
| my2/my3/mod.rs:7:5:7:19 | ...::h | main.rs:56:1:75:1 | fn h |
| my2/my3/mod.rs:8:5:8:9 | super | my2/mod.rs:1:1:23:34 | SourceFile |
| my2/my3/mod.rs:8:5:8:12 | ...::g | my2/mod.rs:3:1:6:1 | fn g |