Skip to content

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

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.

Copy link
Member Author

@TaKO8Ki TaKO8Ki Jun 20, 2023

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)

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=2b950ebb99306f3c8f6d491aab8f84bd

Copy link
Member Author

@TaKO8Ki TaKO8Ki Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// ```
if c == '}' {
return spec;
}
if let Some((_, '>' | '<' | '^')) = self.cur.clone().nth(1) {
spec.fill = Some(c);
self.cur.next();
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/fmt/format-args-issue-112732.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// check-pass

fn main() {
println!("Hello, world! {0:}<3", 2);
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as comments above.

}