考虑以下代码段:
macro_rules! quick_hello {
($to_print:expr) => {
{
let h = "hello";
println!("{}", $to_print)
}
}
}
fn main() {
quick_hello!(h);
}
如果我编译它,我会得到:
error[E0425]: cannot find value `h` in this scope
--> src/main.rs:12:18
|
12 | quick_hello!(h);
| ^ not found in this scope
但是不应该将quick_hello
调用main
扩展为包含该let h = "hello"
语句的块,从而允许我在调用站点将其用作“hello”的速记吗?
我可能会知道这样做是为了保持宏的卫生,但是如果我需要上述行为怎么办?有没有办法“关闭”卫生来实现这一目标?