-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
new uninlined_format_args lint to inline explicit arguments #9233
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @xFrednet (or someone else) soon. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I had a look through most of the TODO
s. Also worth mentioning you can use let chains rather than if_chain
, it plays better with rust_analyzer (though also doesn't get automatically formatted yet)
Thanks @Alexendoo for the review! I made a number of changes based on that, but still a few todos. My biggest concern is how to detect if an argument is also used as precision and/or width. I know some format-related work is being done in the rustc, and there seem to be at least 3 devs involved, so I wonder who/how can coordinate these efforts to be consistent and reuse each other's work. |
If it's not in your TODOs yet, the lint should be integrated into the MSRV system of clippy and be gated on 1.58.0, as that's when format capturing was added. |
☔ The latest upstream changes (presumably #9243) made this pull request unmergeable. Please resolve the merge conflicts. |
@est31 thx, fixed. I think I am done with this lint -- it now solves the majority of cases, and it avoids expanding width/precision arguments by checking if the argument span contains a |
@Alexendoo Do you want to take over the full review? I believe you know the format macro better than me. If you don't have the time, feel free to give it back. I should have more time for Clippy again 🙃 |
Sure! Sounds good to me. I'll take a full look at it once it's unblocked |
Awesome, thank you! r? @Alexendoo |
Thx @Alexendoo ! Is there something i can do to help the #8518 ? Are there any fundamental blocks on that, or is it juts a matter of patiently waiting? :) |
Yeah just a matter of waiting for the large amount of reviewer bandwidth needed |
☔ The latest upstream changes (presumably #9264) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR! I learned something about the format macro and what is possible with it.
The impl LGTM overall, but some housekeeping, like documentation, has to be done still.
@flip1995 thanks for the review! I addressed some of your points, and made a few clarifications. I am still in a bit of a limbo state - waiting for the upstream #8518 conflicts to be resolved, plus now there is #9349 - so I am not certain at which point I should start resolving conflicts and getting it back to the "ready to merge" state again. |
No worries. Let's get the other PRs merged first. You can work on this as you see fit. But also feel free to just let this PR sit as-is until we resolved the other issues. |
Personally I'm inclined to leave it as a known issue for now. It's not limited to just this lint, any other lint working with string literals may have a problem with this style of proc macro, I plan to replace |
bc39697
to
ba320c7
Compare
@Alexendoo ok, thx, I squashed and cleaned up the PR - should be in a good state now. I also added a few more unit tests that would also fail until your changes. |
97a2f80
to
6685596
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just some documentation nits and then it's good for merging
Thank you for the endurance 😄
Good ol' Could give it one final squash too |
Bummer, I can't, I'm at a playground)))) |
I'll do it in a bit. Thanks for all the help!!! |
Implement rust-lang#8368 - a new lint to inline format arguments such as `print!("{}", var)` into `print!("{var}")`. code | suggestion | comment ---|---|--- `print!("{}", var)` | `print!("{var}")` | simple variables `print!("{0}", var)` | `print!("{var}")` | positional variables `print!("{v}", v=var)` | `print!("{var}")` | named variables `print!("{0} {0}", var)` | `print!("{var} {var}")` | aliased variables `print!("{0:1$}", var, width)` | `print!("{var:width$}")` | width support `print!("{0:.1$}", var, prec)` | `print!("{var:.prec$}")` | precision support `print!("{:.*}", prec, var)` | `print!("{var:.prec$}")` | asterisk support code | suggestion | comment ---|---|--- `print!("{0}={1}", var, 1+2)` | `print!("{var}={0}", 1+2)` | Format string uses an indexed argument that cannot be inlined. Supporting this case requires re-indexing of the format string. changelog: [`uninlined_format_args`]: A new lint to inline format arguments, i.e. `print!("{}", var)` into `print!("{var}")`
cd2eef5
to
5a71bbd
Compare
@Alexendoo ok, I think it's finally ready 😀 |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fallout: fix tests to allow uninlined_format_args In order to switch `clippy::uninlined_format_args` from pedantic to style, all existing tests must not raise a warning. I did not want to change the actual tests, so this is a relatively minor change that: * add `#![allow(clippy::uninlined_format_args)]` where needed * normalizes all allow/deny/warn attributes * all allow attributes are grouped together * sorted alphabetically * the `clippy::*` attributes are listed separate from the other ones. * deny and warn attributes are listed before the allowed ones See also #9233, #9525, #9527 cc: `@llogiq` `@Alexendoo` changelog: none
Change uninlined_format_args into a style lint As [previously discussed](#9233 (comment)), the `uninlined_format_args` should probably be a part of the default style because `println!("{}", foo)` is not as concise or easy to understand as `println!("{foo}")` changelog: [`uninlined_format_args`]: change to be the default `style`
Implement #8368 - a new lint to inline format arguments such as
print!("{}", var)
intoprint!("{var}")
.Supported cases
print!("{}", var)
print!("{var}")
print!("{0}", var)
print!("{var}")
print!("{v}", v=var)
print!("{var}")
print!("{0} {0}", var)
print!("{var} {var}")
print!("{0:1$}", var, width)
print!("{var:width$}")
print!("{0:.1$}", var, prec)
print!("{var:.prec$}")
print!("{:.*}", prec, var)
print!("{var:.prec$}")
Known Problems
Supporting this case requires re-indexing of the format string.
Until implemented,
print!("{0}={1}", var, 1+2)
should be changed toprint!("{var}={0}", 1+2)
by hand.changelog: [
uninlined_format_args
]: A new lint to inline format arguments, i.e.print!("{}", var)
intoprint!("{var}")