Skip to content

Commit 84e6178

Browse files
committed
wip
1 parent a25950b commit 84e6178

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub fn hello() {
2+
my_macro!(); // $ item=my_macro
23
println!("Hello, world!"); // $ item=println
34
} // HELLO
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1+
#[macro_use]
2+
mod macros {
3+
macro_rules! my_macro {
4+
() => {
5+
println!("my_macro!");
6+
};
7+
}
8+
}
9+
110
pub mod a_module;

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,8 +1575,12 @@ private predicate unqualifiedPathLookup(ItemNode ancestor, string name, Namespac
15751575
not (
15761576
name = "Self" and
15771577
mid = any(ImplOrTraitItemNode i).getAnItemInSelfScope()
1578-
) and
1578+
)
1579+
|
15791580
ancestor = getOuterScope(mid)
1581+
or
1582+
ns.isMacro() and
1583+
ancestor = mid.getImmediateParentModule()
15801584
)
15811585
}
15821586

@@ -1680,16 +1684,17 @@ private predicate expandsMacro(AstNode macroInvocation, AstNode expansion, Path
16801684
}
16811685

16821686
pragma[nomagic]
1683-
predicate isInMacroFromCrateExpansion(CrateItemNode crate, AstNode n) {
1684-
exists(Path path |
1685-
expandsMacro(_, n, path) and
1686-
crate.getASourceFile().getFile() = resolvePathCand(path).getFile()
1687-
)
1687+
predicate isInMacroExpansion(Path macroDefPath, AstNode macroInvocation, AstNode n) {
1688+
expandsMacro(macroInvocation, n, macroDefPath)
16881689
or
1689-
exists(AstNode mid |
1690-
isInMacroFromCrateExpansion(crate, mid) and
1691-
n.getParentNode() = mid and
1692-
not expandsMacro(mid, n, _)
1690+
isInMacroExpansion(macroDefPath, macroInvocation, n.getParentNode())
1691+
}
1692+
1693+
pragma[nomagic]
1694+
predicate isInMacroFromCrateExpansion(CrateItemNode crate, AstNode macroInvocation, AstNode n) {
1695+
exists(Path macroDefPath |
1696+
isInMacroExpansion(macroDefPath, macroInvocation, n) and
1697+
crate.getASourceFile().getFile() = resolvePathCand(macroDefPath).getFile()
16931698
)
16941699
}
16951700

@@ -1706,7 +1711,7 @@ private ItemNode resolvePathCand0(RelevantPath path, Namespace ns) {
17061711
)
17071712
or
17081713
path.isDollarCrate() and
1709-
isInMacroFromCrateExpansion(result, path) and
1714+
isInMacroFromCrateExpansion(result, _, path) and
17101715
ns = result.getNamespace()
17111716
or
17121717
result = resolvePathCandQualified(_, _, path, ns)

0 commit comments

Comments
 (0)