Closed
Description
It looks like something relating to hygiene in declarative macros makes them fail when used in patterns. This code looks like it should compile:
#![feature(decl_macro)]
pub struct Foo {
bar: u32,
}
pub macro pattern($a:pat) {
Foo { bar: $a }
}
fn main() {
match (Foo { bar: 3 }) {
pattern!(3) => println!("Test OK"),
_ => unreachable!(),
}
}
But instead, it does this:
Compiling playground v0.0.1 (file:///playground)
error[E0026]: struct `Foo` does not have a field named `bar`
--> src/main.rs:7:11
|
7 | Foo { bar: $a }
| ___________^
8 | | }
9 | |
10 | | fn main() {
11 | | match (Foo { bar: 3 }) {
12 | | pattern!(3) => println!("Test OK"),
| | ---------^-
| |_________|________|
| | struct `Foo` does not have field `bar`
| in this macro invocation
error[E0027]: pattern does not mention field `bar`
--> src/main.rs:7:5
|
7 | Foo { bar: $a }
| ^^^^^^^^^^^^^^^ missing field `bar`
...
12 | pattern!(3) => println!("Test OK"),
| ----------- in this macro invocation
error: aborting due to 2 previous errors
error: Could not compile `playground`.
To learn more, run the command again with --verbose.