Currently, macro_rules!
enforces follow-set ambiguity restrictions that prevent patterns like $i:expr : ...
(an expr
fragment directly followed by a colon). This appears to stem from historical ambiguity with type ascription syntax (expr: Ty
), which allowed type annotations in expressions.
https://doc.rust-lang.org/reference/macros-by-example.html#r-macro.decl.follow-set.token-expr-stmt
However, since type ascription was officially removed via De-RFC #2522, the grammar no longer permits a colon directly after an expression.
Given that the original ambiguity source (type ascription) no longer exists:
- Could we relax the follow-set restrictions for
expr
fragments followed by:
in macros? - Are there remaining ambiguities I might be overlooking?
This change would unblock macro patterns like:
macro_rules! my_macro {
($i:expr : $t:ty) => { /* ... */ };
}
Without reintroducing parsing conflicts. I'm curious if there's either:
a) A technical reason this restriction must remain
b) Consensus that this could be safely changed
Would appreciate insights from compiler/parser experts!