Open
Description
What it does
Try to catch bad macro param patterns, and suggest better ones:
- Replace
<anything>, $($e:expr),*
with<anything> $(, $e:expr)* $(,)?
- this must also replace all usages of
<anything>, $($e,)*
with<anything> $(, $e)*
- this must also replace all usages of
- Add missing trailing comma - can be fixed by adding
$(,)?
. See also Lint macro definitions that don't allow trailing commas #1848 - ? some other bad patterns ?
Lint Name
bad_macro_param_pattern
Category
suspicious
Advantage
- keeps macro declarations more consistent
- catches common errors like using format-like macro:
my_macro!("{}", foo)
not being replaceable bymy_macro!("{foo}")
(i.e. it is no longer requires a single comma to always be present)
Drawbacks
possible formatting issues on auto-fix
Example
macro_rules! my_macro {
($fmt:literal, $($e:expr),*) => {
println!($fmt, $($e,)*)
}
}
Could be written as:
macro_rules! my_macro {
($fmt:literal $(, $e:expr)* $(,)?) => {
println!($fmt $(, $e)*)
}
}