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
This would lint against use of $smth in the expansion part of a macro_rules! if smth is not a capture. While such a pattern could be used in a recursive macro, it is being phased out, so in practice it is likely an typo, especially if the name of smth is close to an actual capture.
Detect potential bugs in macros.
Macros are hard to debug and have very little compile-time validity checks. Complex recursive macros are very complex, and can have many rules. Any tool to improve that is good.
Drawbacks
There is a possibility of false positives
Example
macro_rules! testing {($testing:ty) => {$testin}}
Will never be usable because testin is not a capture (notice the missing g) is not a capture.
Implementing such a lint is probably tricky because the AST for macro definitions only has the raw TokenStream available, making it difficult to look for anything (even just finding macro matchers). So this sounds like it'd require some manual parsing.
Other similar lints have done this by looking for expansions, but that doesn't seem viable here since at that point you would get a proper compile error instead
What it does
This would lint against use of
$smth
in the expansion part of amacro_rules!
ifsmth
is not a capture. While such a pattern could be used in a recursive macro, it is being phased out, so in practice it is likely an typo, especially if the name ofsmth
is close to an actual capture.See dzamlo/rust-bitfield#40 for the case that prompted this lint suggestion.
Advantage
Macros are hard to debug and have very little compile-time validity checks. Complex recursive macros are very complex, and can have many rules. Any tool to improve that is good.
Drawbacks
There is a possibility of false positives
Example
Will never be usable because
testin
is not a capture (notice the missingg
) is not a capture.it should instead be written as:
The text was updated successfully, but these errors were encountered: