-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Accept "{:}<"
in format macro parser
#112773
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
Conversation
r? @jackh726 (rustbot has picked a reviewer for you, use r? to override) |
"{:}<"
in format macro parser
For the record, this code would now behave differently, right? fn main() {
println!("{:}<3}", 0);
} According to the linked issue, the format spec allows any fill character, so shouldn't we be preserving this old behavior? |
@compiler-errors Yes. After this change is applied, this case causes an error like the following, In the old parser, it is compiled successfully. I think this might be wrong behavior and new error looks better.
I guess we don't have detailed specification for formatting and the current behavior is regarded as a specification? Should I avoid changing the behavior of the format macro parse and just add a diagnostic for this case? Given the following code: fn main() {
println!("{:}<3}", 0);
} Before this change is applied: Compiled successfully After the change is applied:
|
Nominating for T-libs-api I think, because this has to do with the specification of the format macro, and it's not strictly a fix. |
@@ -626,6 +626,13 @@ impl<'a> Parser<'a> { | |||
|
|||
// fill character | |||
if let Some(&(_, c)) = self.cur.peek() { | |||
// The following case should be compiled successfully. | |||
// ``` | |||
// format!("foo {:}<", 2); |
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.
There's a missing close-brace here.
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.
You mean the following brace is not a close-brace?
format!("foo {:}<", 2);
↑
But the current rustc can compile this successfully.
format!("{:}", 2)
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.
They can also be compiled.
fn main() {
format!("{:} <", 2);
}
fn main() {
format!("{}<", 2);
}
// check-pass | ||
|
||
fn main() { | ||
println!("Hello, world! {0:}<3", 2); |
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.
There's a missing close-brace here.
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.
Same as comments above.
We discussed this in the libs-api meeting today. We're not sure if we can go forward with this, since this would be a breaking change: you could no longer set I mentioned that |
Thank you for discussing it. I see. The example you provided would cause an error like the following after this change is applied. Should
Ok. I'll create an issue in clippy and work on it when I have time. |
Today, every single character is available as fill character. "Every single character except }" doesn't seem like a big improvement. (What about '{' or other potentially confusing ones?) I agree |
Understood. You're right. I'll close this pull request. |
I think this should also be compiled successfully.
Fixes #112732
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=5a69e2326988b6150c62087ef60ecf2f