Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
| exe/src/main.rs:5:1:7:1 | fn main |
| lib/src/a_module/mod.rs:1:1:3:1 | fn hello |
| lib/src/a_module/mod.rs:1:1:4:1 | fn hello |
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub fn hello() {
println!("Hello, world!");
my_macro!(); // $ item=my_macro
println!("Hello, world!"); // $ item=println
} // HELLO
9 changes: 9 additions & 0 deletions rust/ql/integration-tests/hello-workspace/lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
#[macro_use]
mod macros {
macro_rules! my_macro {
() => {
println!("my_macro!");
};
}
}

pub mod a_module;
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
| Inconsistencies - Path resolution | 0 |
| Inconsistencies - SSA | 0 |
| Inconsistencies - data flow | 0 |
| Lines of code extracted | 9 |
| Lines of user code extracted | 9 |
| Macro calls - resolved | 2 |
| Macro calls - total | 2 |
| Lines of code extracted | 15 |
| Lines of user code extracted | 15 |
| Macro calls - resolved | 5 |
| Macro calls - total | 5 |
| Macro calls - unresolved | 0 |
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
| Inconsistencies - Path resolution | 0 |
| Inconsistencies - SSA | 0 |
| Inconsistencies - data flow | 0 |
| Lines of code extracted | 9 |
| Lines of user code extracted | 9 |
| Macro calls - resolved | 2 |
| Macro calls - total | 2 |
| Lines of code extracted | 15 |
| Lines of user code extracted | 15 |
| Macro calls - resolved | 5 |
| Macro calls - total | 5 |
| Macro calls - unresolved | 0 |
8 changes: 8 additions & 0 deletions rust/ql/lib/codeql/rust/elements/internal/MacroCallImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ private import codeql.rust.elements.internal.generated.MacroCall
*/
module Impl {
private import rust
private import codeql.rust.internal.PathResolution

pragma[nomagic]
predicate isInMacroExpansion(AstNode root, AstNode n) {
Expand Down Expand Up @@ -44,5 +45,12 @@ module Impl {
isInMacroExpansion(this, result) and
this.getTokenTree().getLocation().contains(result.getLocation())
}

/**
* Gets the macro definition that this macro call resolves to.
*
* The result is either a `MacroDef` or a `MacroRules`.
*/
Item resolveMacro() { result = resolvePath(this.getPath()) }
}
}
Loading