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

Suggest format!("{x}") syntax when possible #8675

Closed
digama0 opened this issue Apr 10, 2022 · 2 comments
Closed

Suggest format!("{x}") syntax when possible #8675

digama0 opened this issue Apr 10, 2022 · 2 comments
Labels
A-lint Area: New lints

Comments

@digama0
Copy link
Contributor

digama0 commented Apr 10, 2022

What it does

Given a use of a format macro, suggest to use the format!("{x}") syntax when applicable.

Lint Name

format_args_capture

Category

pedantic

Advantage

  • Code is shorter and more readable
  • Increases awareness of the new syntax

Drawbacks

  • Increases MSRV for projects that care about that

Example

let x = 2;
println!("{}", x);
println!("{x}", x = x);
println!("{y}", y = x); // untouched because variable name doesn't match

Could be written as:

let x = 2;
println!("{x}");
println!("{x}");
println!("{y}", y = x); // untouched because variable name doesn't match
@digama0 digama0 added the A-lint Area: New lints label Apr 10, 2022
@digama0 digama0 changed the title Suggest format_args_capture Suggest format!("{x}") syntax when possible Apr 10, 2022
@jplatte
Copy link
Contributor

jplatte commented Apr 12, 2022

Duplicate of #8368.

@giraffate
Copy link
Contributor

Thanks for suggesting a new lint!

I'm closing this because of #8675 (comment).

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

3 participants