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 use of captured format args #9618

Closed
kornelski opened this issue Oct 9, 2022 · 1 comment
Closed

Suggest use of captured format args #9618

kornelski opened this issue Oct 9, 2022 · 1 comment
Labels
A-lint Area: New lints

Comments

@kornelski
Copy link
Contributor

What it does

In edition 2021 format! and related macros have a new ability to use implicitly captured variables instead of positional arguments: format!("hello {name}");

Lint Name

format_uncaptured_variables

Category

pedantic

Advantage

A lint with an auto-fix could help migrate codebases to the new style. Opposite of #5404.

Drawbacks

format! with a mix of captured and positional args may be confusing:

format("{} {second}", x.first);

so the lint could be limited to cases where all args can be captured.

Example

format!("hello {:^5}", name);

Could be written as:

format!("hello {name:^5}");
@kornelski kornelski added the A-lint Area: New lints label Oct 9, 2022
@kraktus
Copy link
Contributor

kraktus commented Oct 10, 2022

Already implemented on nightly as uninlined_format_args

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