Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions rust/ql/integration-tests/hello-workspace/exe/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use lib::a_module::hello; // $ item=HELLO

use lib::my_macro2; // $ item=my_macro2

mod a_module;

fn main() {
my_macro2!(); // $ item=my_macro2
hello(); // $ item=HELLO
}
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 |
| exe/src/main.rs:7:1:10:1 | fn main |
| 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_macro2!(); // $ item=my_macro2
println!("Hello, world!"); // $ item=println
} // HELLO
16 changes: 16 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,17 @@
#[macro_use]
mod macros {
#[macro_export]
macro_rules! my_macro1 {
() => {
println!("my_macro!");
};
}
#[macro_export]
macro_rules! my_macro2 {
() => {
$crate::my_macro1!();
};
}
}

pub mod a_module;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testFailures
resolveDollarCrate
| exe/src/main.rs:8:5:8:14 | $crate | lib/src/lib.rs:0:0:0:0 | Crate([email protected]) |
| lib/src/a_module/mod.rs:2:5:2:14 | $crate | lib/src/lib.rs:0:0:0:0 | Crate([email protected]) |
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
import rust
import codeql.rust.internal.PathResolution
import utils.test.PathResolutionInlineExpectationsTest

query predicate resolveDollarCrate(RelevantPath p, Crate c) {
c = resolvePath(p) and
p.isDollarCrate() and
p.fromSource() and
c.fromSource()
}
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 | 21 |
| Lines of user code extracted | 21 |
| Macro calls - resolved | 10 |
| Macro calls - total | 10 |
| 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 | 21 |
| Lines of user code extracted | 21 |
| Macro calls - resolved | 10 |
| Macro calls - total | 10 |
| 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