-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
A-lintArea: New lintsArea: New lints
Description
What it does
Warn on format! within the arguments of another macro that does formatting such as format! itself, write! or println!.
Suggests replacing the inner format! call with format_args! or inlining it entirely (see example).
Categories (optional)
- Kind: style / perf
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 the format! changed to format_args! or inlined entirely. I'm not sure how hard it would be to detect these cases.
Example
println!("error: {}", format!("something failed at {}", Location::caller()));Could be written as:
println!("error: {}", format_args!("something failed at {}", Location::caller()));or inlined entirely (when the argument is used exactly once like here):
println!("error: something failed at {}", Location::caller());Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lints