-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)Area: Declarative macros 2.0 (#39412)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-maybe-future-editionSomething we may consider for a future edition.Something we may consider for a future edition.T-langRelevant to the language teamRelevant to the language teamWG-macrosWorking group: MacrosWorking group: Macros
Description
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
Metadata
Metadata
Assignees
Labels
A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)Area: Declarative macros 2.0 (#39412)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-maybe-future-editionSomething we may consider for a future edition.Something we may consider for a future edition.T-langRelevant to the language teamRelevant to the language teamWG-macrosWorking group: MacrosWorking group: Macros