Skip to content
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

Useless format!/to_string in argument of function accepting fmt::Display #8178

Open
GoldsteinE opened this issue Dec 27, 2021 · 2 comments
Open
Labels
A-lint Area: New lints

Comments

@GoldsteinE
Copy link

GoldsteinE commented Dec 27, 2021

What it does

Detects the use of format!() and .to_string() in arguments to a function expecting impl fmt::Display.

(Possible duplicate of #3021, #3156)

Lint Name

useless_format

Category

perf, pedantic

Advantage

  • Remove useless allocation

Drawbacks

  • May be hard to implement?

Example

fn foo(_: impl std::fmt::Display) {}

foo("xyz".to_string());
foo(format!("{} {}", 1, 2));

Could be written as:

fn foo(_: impl std::fmt::Display) {}

foo("xyz");
foo(format_args!("{} {}", 1, 2));
@GoldsteinE GoldsteinE added the A-lint Area: New lints label Dec 27, 2021
@camsteffen
Copy link
Contributor

For .to_string(), this could be an enhancement of unnecessary_to_owned.

I'm not sure about suggesting format_args! because if it is used multiple times there could be a negative perf impact.

@ghost
Copy link

ghost commented Aug 18, 2022

@rustbot claim

@rustbot rustbot assigned ghost Aug 18, 2022
@ghost ghost removed their assignment Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

2 participants