Creating environment for closure in a macro in Rust
问题 I'm trying to achieve something like this (simplified): macro_rules! atest { ($closure:tt) => { let x = 5; println!("Result is {}", $closure()) }; } fn main() { //let x = 50; atest!((|| 5 + x)); } It does not work because the argument to the atest macro is considered by the compiler before macro evaluation: error[E0425]: cannot find value `x` in this scope --> src/main.rs:10:20 | 10 | atest!((|| 5 + x)); | ^ not found in this scope Is it possible to make this work? My understanding was that