Skip to content

Lint for use of format_args that could use format args capture #8452

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

Closed
5225225 opened this issue Feb 20, 2022 · 2 comments
Closed

Lint for use of format_args that could use format args capture #8452

5225225 opened this issue Feb 20, 2022 · 2 comments
Labels
A-lint Area: New lints

Comments

@5225225
Copy link
Contributor

5225225 commented Feb 20, 2022

What it does

If the user writes some expression that uses format_args where any of the arguments could be captured, lint with a suggestion to have as many captures as possible.

This lint would have a suggestion category of MachineApplicable so it can be used to bulk move to using format args capture.

Not entirely sure which category this would belong in. I'm thinking either restriction (so you use this mostly as a refactoring tool, deny the lint and then cargo clippy fix), or style because it is a style matter. Depends how controversial the lint is.

I feel it would be incredibly noisy on any nontrivial crate, so making it warn by default might be a bad idea.

Lint Name

uncaptured_format_args

Category

style, restriction

Advantage

Shorter, and the name of the argument is inline directly in the code.

Drawbacks

If you have multiple arguments, and only some of them can be made inline, then the arguments will be out of order.

This could be mitigated against by only linting if we can move all of the arguments, with a configuration option to lint on all of them? That or 2 different lints.

Example

let x = 1;
let y = format!("{}, {}", x, 10);

Could be written as:

let x = 1;
let y = format!("{x}, {}", 10);
@5225225 5225225 added the A-lint Area: New lints label Feb 20, 2022
@giraffate
Copy link
Contributor

It seems to be a duplicate of #8368.

@5225225
Copy link
Contributor Author

5225225 commented Feb 21, 2022

Ah, you're right. Didn't find that in my searching, my bad!

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