-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lint suggestion: nested format! #7667
Comments
Lint name idea: To implement, I would start with |
@camsteffen If I were to implement this, would it be too invasive if I were to change Currently, it strictly handles rust-clippy/clippy_utils/src/higher.rs Line 488 in fb17671
|
@smoelius I think I would add something like this, on top of what we already have: enum FormatLikeExpn {
Assert(AssertExpn),
Format(FormatExpn),
FormatArgs(FormatArgsExpn),
Print(PrintExpn),
} so we still have the option of parsing a specific macro. |
OK. Thanks for your response. I'm going to play with this and see what makes sense. |
Add `format_in_format_args` and `to_string_in_format_args` lints Fixes #7667 and #7729 I put these in `perf` since that was one of `@jplatte's` suggestions, and `redundant_clone` (which I consider to be similar) lives there as well. However, I am open to changing the category or anything else. r? `@camsteffen` changelog: Add `format_in_format_args` and `to_string_in_format_args` lints
What it does
Warn on
format!
within the arguments of another macro that does formatting such asformat!
itself,write!
orprintln!
.Suggests replacing the inner
format!
call withformat_args!
or inlining it entirely (see example).Categories (optional)
The recommended code is both shorter and avoids a temporary allocation.
Drawbacks
There could be situations when the outer macro is
format_args!
where lifetimes don't work out with theformat!
changed toformat_args!
or inlined entirely. I'm not sure how hard it would be to detect these cases.Example
Could be written as:
or inlined entirely (when the argument is used exactly once like here):
The text was updated successfully, but these errors were encountered: