You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
macro_rules! thinks use is an ident. It isn't. #40569
This code should compile successfully. However, it fails complaining that it can't decide whether use is an ident or not (hint: it isn't). It also shouldn't be trying to match use as an ident because of the semicolon, but that's a broader/deeper issue with macro_rules!
I suppose, ident can be backward compatibly restricted to reject keywords and reserved identifiers with exception of path segment keywords super, self and Self (because you may want to write things like $seg: ident => $seg::foo::bar), but I don't see much benefit from such restriction.
The second case given in this issue is a very concrete benefit from that restriction. 😄
The repetition thing is because macro_rules just doesn't attempt any backtracking. This has been reported before. You need to put a constant token in between (e.g. struct). It's obviously not backwards compatible to change the definition of ident now, I don't know what @petrochenkov was talking about in that quote...
Activity
petrochenkov commentedon Mar 16, 2017
identmatcher accepts keywords (and also reserved keywords) by design (see very similar issue aboutself- #27899 (comment) cc @nrc).sgrif commentedon Mar 16, 2017
From that issue:
The second case given in this issue is a very concrete benefit from that restriction. 😄
sgrif commentedon Mar 16, 2017
It looks like repeaters can pretty easily confuse
macro_rules!even in more ridiculous cases. e.g.causes it to complain that it doesn't know if
#is supposed to be an ident or notdurka commentedon Mar 16, 2017
The repetition thing is because
macro_rulesjust doesn't attempt any backtracking. This has been reported before. You need to put a constant token in between (e.g.struct). It's obviously not backwards compatible to change the definition ofidentnow, I don't know what @petrochenkov was talking about in that quote...dtolnay commentedon Mar 16, 2017
One specific common macro that this would break is Serde's
forward_to_deserialize_anywhich accepts "struct" and "enum" as idents.Auto merge of #42913 - kennytm:fix-40569-ident-without-backtrack, r=j…
petrochenkov commentedon Aug 14, 2019
Closing as works-as-expected and cannot-be-changed.