Uh oh!
There was an error while loading. Please reload this page.
Emit warning when named arguments are used positionally in format - #98580
Conversation
rust-highfive
commented
Jun 27, 2022
r? @cjgillot (rust-highfive has picked a reviewer for you, use r? to override) |
PrestonFrom
commented
Jun 27, 2022
r? @estebank I'm not sure if I should override who rustbot picked to review this, but I thought you might have a little more context. |
estebank
commented
Jun 27, 2022
@bors try |
bors
commented
Jun 27, 2022
⌛ Trying commit aa875b67b4e6be07f55065129a3b4426d720de28 with merge 768af4cba83356e997782d009ecca0564739e9fc... |
PrestonFrom
commented
Jun 27, 2022
Uh-oh! I will look into this! I must have missed something when compiling locally. |
This comment has been minimized.
This comment has been minimized.
bors
commented
Jun 27, 2022
💔 Test failed - checks-actions |
This comment has been minimized.
This comment has been minimized.
estebank
commented
Jun 27, 2022
The fact that we have failures in our own codebase makes me think that this error is way too common for an outright error. We'll have to turn it into a warn by default lint very likely. Still interested in gauging what the real incidence is. |
PrestonFrom
commented
Jun 27, 2022
@estebank Looking into this, it turns out I made a bad assumption in how I was checking for unused named arguments, and the error should not have been emitted! I'll let you know when I figure out how to do this correctly. Sorry for the delay! |
Mark-Simulacrum
commented
Jun 27, 2022
FWIW, this has been discussed by T-lang in the past and at the time there was positive sentiment towards a lint on this (#45256 (comment)). |
PrestonFrom
commented
Jun 27, 2022
@Mark-Simulacrum thank you for sharing this! Would I be correct in thinking that this means a warning should be emitted instead of an error? |
Mark-Simulacrum
commented
Jun 27, 2022
I would expect so, it should be a lint though -- maybe even we can reuse something like unused variable for it, but @estebank can say more on the naming front. |
PrestonFrom
commented
Jun 27, 2022
Oh, I see -- this should not be done in |
This comment has been minimized.
This comment has been minimized.
estebank
commented
Jun 28, 2022
The new error shows that the "liveness" check needs to account for the formatting position (when used after the |
There was a problem hiding this comment.
Oh, it seems like you were doing that already? 🤔
There was a problem hiding this comment.
It turns out I missed the same case but for precision!
estebank
commented
Jun 28, 2022
It shouldn't need to be in clippy, I think this warrants a |
PrestonFrom
commented
Jun 28, 2022
@estebank Thank you! I will take a look at |
There was a problem hiding this comment.
Ideally the end result would look something like this:
error: named string formatting argument is not used by name
--> $DIR/issue98466.rs:4:26
|
LL | println!("_x is {}", _x = 5);
| -- ^^ this named argument is only referred to by position in the formatting string
| |
| this formatting argument uses named argument `_x` by position
|
= note: lint `#[deny(named_formatting_arg_by_pos)]` enabled by default
help: use the named argument by name to avoid ambiguity
|
LL | println!("_x is {_x}", _x = 5);
| ++
There was a problem hiding this comment.
That seems reasonable to me! Still working on getting the lint to actually be emitted.
There was a problem hiding this comment.
What I ended up with looks a little different -- since I used span_suggestion the help part got rolled in with the suggestion. Should I be using a different method?
Also, the lint is currently Warn instead of Deny, since it seems like it's been valid to use named arguments positionally for some years. Would Deny be better?
This comment has been minimized.
This comment has been minimized.
f20ee9f to
abf6741ComparePrestonFrom
commented
Jul 8, 2022
@estebank Thank you for the review and suggestions! I believe I have addressed them all and squashed (after running |
There was a problem hiding this comment.
This can also be written as
| .iter() | |
| .map(|piece| { | |
| letmut piece = piece.clone(); | |
| .iter() | |
| .cloned() | |
| .map(|mut piece| { |
There was a problem hiding this comment.
@estebank Thanks for the suggestion! Did you want me to fix this? (I wasn't sure since it was in the queue.)
There was a problem hiding this comment.
There's no need right now if you can't get to it, but keep it in mind for the future. If you do fix it, I can reapprove :)
There was a problem hiding this comment.
I force pushed the fix -- I hope that was what was expected!
estebank
commented
Jul 8, 2022
@bors r+ |
bors
commented
Jul 8, 2022
📌 Commit abf6741408fb31701168c6150c077e98cdc82b4b has been approved by It is now in the queue for this repository. |
PrestonFrom
commented
Jul 11, 2022
@estebank I hope I didn’t break anything by doing this, but I updated the name of the PR since it’s a warning instead of an error now. I also pushed the change to use cloned. Do I need another approval from you or do I just wait for bors now? |
bors
commented
Jul 13, 2022
☔ The latest upstream changes (presumably #99203) made this pull request unmergeable. Please resolve the merge conflicts. |
PrestonFrom
commented
Jul 13, 2022
Oh I forgot the no merging rule. I'll rebase and force push. |
Addresses Issue 98466 by emitting a warning if a named argument is used like a position argument (i.e. the name is not used in the string to be formatted). Fixesrust-lang#98466
PrestonFrom
commented
Jul 13, 2022
I think this is good now! |
estebank
commented
Jul 13, 2022
@bors r+ |
bors
commented
Jul 13, 2022
Rollup of 6 pull requests Successful merges: - rust-lang#98072 (Add provider API to error trait) - rust-lang#98580 (Emit warning when named arguments are used positionally in format) - rust-lang#99000 (Move abstract const to middle) - rust-lang#99192 (Fix spans for asm diagnostics) - rust-lang#99222 (Better error message for generic_const_exprs inference failure) - rust-lang#99236 (solaris: unbreak build on native platform) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Addresses Issue 98466 by emitting an error if a named argument
is used like a position argument (i.e. the name is not used in
the string to be formatted).
Fixes#98466