Motivating example (playground link):
macro_rules! foo {
($a:literal) => {
foo!(@inner $a);
};
(@inner true) => {
println!("true");
};
(@inner false) => {
println!("false");
};
}
fn main() {
foo!(true);
foo!(false);
}
The above fails to compile because literal does not forward to exact matches, but it doesn't seem like there is any reason it shouldn't. ident or tt can be used, but loosening restrictions can cause other problems.
This probably couldn't be changed without an edition depending on fallout, but we can probably make sure this works with macros 2.0.
The reference makes a comment about forwarding here: https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment
Motivating example (playground link):
The above fails to compile because
literaldoes not forward to exact matches, but it doesn't seem like there is any reason it shouldn't.identorttcan be used, but loosening restrictions can cause other problems.This probably couldn't be changed without an edition depending on fallout, but we can probably make sure this works with macros 2.0.
The reference makes a comment about forwarding here: https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment