to_string() in a format string when format specifiers are used (eg :<20) is NOT redundant #8855
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Uh oh!
There was an error while loading. Please reload this page.
Summary
It is not true that
a) println!("{:<20}", struct.to_string());
gives the same result as
b) println!("{:<20}", struct)
It depend on how the formatter is written.
Line a) uses the default "{}" display to render a string then renders the string using the formatting rules :<20
Whereas b) uses the formatting rules of the struct's display, not the string's display trait impl.
Many dsiplay impls for objects do not have logic to cater for alignment for instance, but using struct.to_string() and then formatting with alignment format specifiiers DOES give alignment.
Clippy "fixing" such lines results in behavioural change.
I think clippy should flag only when the format is "{}"
Lint Name
to_string_in_format_args
Reproducer
I tried this code:
I saw this happen:
This is related to #7729
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: