mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Rust: Fix spurious path resolution
The annotated impl block was filtered away, but it's children where not. This caused the associated type `Foo` to appear as if it was an item in the scope outside of the impl block.
This commit is contained in:
@@ -78,6 +78,24 @@ private ItemNode getAChildSuccessor(ItemNode item, string name, SuccessorKind ki
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `n` is superceded by an attribute macro expansion. That is, `n` is
|
||||
* an item or a transitive child of an item with an attribute macro expansion.
|
||||
*/
|
||||
predicate supercededByAttributeMacroExpansion(AstNode n) {
|
||||
n.(Item).hasAttributeMacroExpansion()
|
||||
or
|
||||
exists(AstNode parent |
|
||||
n.getParentNode() = parent and
|
||||
supercededByAttributeMacroExpansion(parent) and
|
||||
// Don't exclude expansions themselves as they supercede other nodes.
|
||||
not n = parent.(Item).getAttributeMacroExpansion() and
|
||||
// Don't consider attributes themselves to be superceded. E.g., in `#[a] fn
|
||||
// f() {}` the macro expansion supercedes `fn f() {}` but not `#[a]`.
|
||||
not n instanceof Attr
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* An item that may be referred to by a path, and which is a node in
|
||||
* the _item graph_.
|
||||
@@ -158,7 +176,7 @@ private ItemNode getAChildSuccessor(ItemNode item, string name, SuccessorKind ki
|
||||
abstract class ItemNode extends Locatable {
|
||||
ItemNode() {
|
||||
// Exclude items that are superceded by the expansion of an attribute macro.
|
||||
not this.(Item).hasAttributeMacroExpansion()
|
||||
not supercededByAttributeMacroExpansion(this)
|
||||
}
|
||||
|
||||
/** Gets the (original) name of this item. */
|
||||
|
||||
@@ -784,7 +784,7 @@ mod impl_with_attribute_macro {
|
||||
|
||||
pub fn test() {
|
||||
// This should resolve to the struct, not the associated type.
|
||||
let _x: Foo; // $ item=IFoo SPURIOUS: item=IATrait_i64_Foo
|
||||
let _x: Foo; // $ item=IFoo
|
||||
} // impl_with_attribute_macro::test
|
||||
}
|
||||
|
||||
|
||||
@@ -356,7 +356,6 @@ resolvePath
|
||||
| main.rs:779:21:779:23 | i64 | {EXTERNAL LOCATION} | struct i64 |
|
||||
| main.rs:781:11:781:13 | i64 | {EXTERNAL LOCATION} | struct i64 |
|
||||
| main.rs:787:17:787:19 | Foo | main.rs:772:5:772:15 | struct Foo |
|
||||
| main.rs:787:17:787:19 | Foo | main.rs:779:27:782:9 | type Foo |
|
||||
| main.rs:792:5:792:6 | my | main.rs:1:1:1:7 | mod my |
|
||||
| main.rs:792:5:792:14 | ...::nested | my.rs:1:1:1:15 | mod nested |
|
||||
| main.rs:792:5:792:23 | ...::nested1 | my/nested.rs:1:1:17:1 | mod nested1 |
|
||||
|
||||
Reference in New Issue
Block a user