Closed
Description
Does macro hygiene simply not work with respect to static identifiers in our model of syntax expansion?
For example:
macro_rules! foo {
($e:expr) => ({
let value = $e;
value
})
}
fn main() {
static value: i32 = 4; // comment out this line and things work
let x = foo!(3);
println!("x: {}", x);
}
I would have hoped that my use of the name value
in the macro foo
is irrelevant to the use of the name value
in the body of main
.
But currently one gets:
<anon>:3:13: 3:18 error: static variables cannot be referenced in a pattern, use a `const` instead
<anon>:3 let value = $e;
^~~~~
<anon>:1:1: 6:2 note: in expansion of foo!
<anon>:10:13: 10:21 note: expansion site
error: aborting due to previous error
playpen: application terminated with error code 101
This is a shame because the box-desugaring #22181 expands into a { ... let value = ...; ... }
, and there is a static binding of value
in src/test/run-pass/drop-struct-as-object.rs