chore: tag format_ident with #[clippy::format_args]#324
chore: tag format_ident with #[clippy::format_args]#324nyurik wants to merge 1 commit intodtolnay:masterfrom
format_ident with #[clippy::format_args]#324Conversation
Since 1.85, Clippy supports `#[clippy::format_args]` attribute - see [docs](https://doc.rust-lang.org/clippy/attribs.html#clippyformat_args) - this way all users of this macro will get the benefits of clippy format arg validations. The only possible problem is that `format_ident!("Foo{bar}")` might not be edition2021+ compliant (i.e. may treat that string as verbatim). I suspect it might be ok to modify the macro implementation to always treat a single param macro as a format string because anything with curlies in it is not a valid identifier.
dtolnay
left a comment
There was a problem hiding this comment.
Could you share an example of a diagnostic output that this PR would cause clippy to emit?
|
From https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-185 (implemented in rust-lang/rust-clippy#9948) - many existing lints, namely Note that the above list is not complete - any Clippy lint that internally calls is_format_macro() will do it too. |
|
I know about that, and I have used this feature in dtolnay/anyhow#426. But specifically for |
|
Specifically, in the following part of the expansion, notice how any $arg would always be evaluated outside the context of a Lines 163 to 165 in ad9fb40 |
|
You are right, it seems current Clippy logic either does not see this macro as a valid candidate for evaluation, or some other thing. I could try to look into Clippy logic itself, or what would you suggest? |
Since 1.85, Clippy supports
#[clippy::format_args]attribute - see docs - this way all users of this macro will get the benefits of clippy format arg validations.The only possible problem is that
format_ident!("Foo{bar}")might not be edition2021+ compliant (i.e. may treat that string as verbatim). I suspect it might be ok to modify the macro implementation to always treat a single param macro as a format string because anything with curlies in it is not a valid identifier.Fixes #290
Related #206