-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Named format arguments can be used as positional #93415
Comments
Perhaps #93378? |
Looks to be it, beat me to it by a day it looks like. (I still think this working even with explicit named parameters should be linted against, though.) |
format_args!("{what}{}")
works unexpectedly (named format arguments can be used as positional)
I restricted this just to the "named arguments can be used as positional" case, since #93378 is getting fixed for the more obviously bad case of |
Note that if this gets upgraded to a hard error, #93394 can be backed out, as it exists just so that implicit captures don't count as positional arguments (but named arguments still do). |
I agree with @CAD97 said: While it can be confusing, I'm not sure it's something we should consider a bug, as this behaviour has been stable for almost six years. A lint that warns about it could be reasonable. Maybe something like this:
|
@m-ou-se I don't think this behavior was documented. I did stumble upon it even before opening #93378 when writing a derive with Since this behavior wasn't documented we shouldn't consider it as a valid usage of formatting macros. If we make it a hard error I am sure a bunch of code will break (probably revealing real bugs though!), but we can make it at least a compatibility warning similar to how we got rid of But, I'd rather give it to |
Sure, that's basically the same lint that was already suggested. Whether we tag that as a future compaibility lint or not is debatable. I don't see any reason to make this stronger than a warning. A warning helps against bugs, but anything stronger doesn't really seem to have much extra value. I don't think it makes sense to warn if any of your dependencies trigger the lint, for example.
As Rust usage outside of open-source grows, Crater is becoming less and less a reliable indicator for these sort of things. Especially since it mostly tests libraries, while |
#98580 will lint against named args used only as named, so it won't trigger for this case. |
rust-lang/rust-clippy#9040 will cover this case. |
This warns on the current stable (1.71):
I think we should consider making this a hard error in edition2024, but otherwise this issue can be considered resolved. |
@rustbot label -needs-triage-legacy |
As mentioned above, this is still accepted but gives a warning now. We can still consider making this a hard error in a future edition. I don't think it's worth it doing anything edition-specific here. A warning seems just fine. I don't think we'd gain anything by changing @rfcbot close |
Team member @m-ou-se has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to close, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
Per FCP, closing as completed. |
I tried this code:
I expected to see this happen:
Instead, this happened: explanation
Standard Error
Standard Output
Meta
This happens on current 1.60.0-nightly (2022-01-27 21b4a9c), and back to rustc 1.12.01. On rustc 1.11.0, it gives
Given how old this "support" is, I don't know if this can be classified as a bug anymore, or if it's just more of a misfeature at this point. IMHO, this should at least get a lint, or even a future-compat lint if that's considered reasonable.
Footnotes
So I guess this would be considered regression-from-stable-to-stable? 🙃 ↩
The text was updated successfully, but these errors were encountered: