这是一些库代码的简化示例。由于某种原因,函数m
在该范围内是可调用的,而闭包n
却不是:
pub trait TestTrait {
fn testFunc();
}
macro_rules! custom {
($body:expr) => {
fn testFunc() {
fn m() {}
let n = || {};
$body
}
};
}
macro_rules! int_custom {
() => {
impl TestTrait for i32 {
custom!({
m();
n();
});
}
};
}
int_custom!();
fn main() {
println!("Test");
}
error[E0425]: cannot find function `n` in this scope
--> src/main.rs:20:17
|
20 | n();
| ^ not found in this scope
...
26 | int_custom!();
| -------------- in this macro invocation
为什么会这样?