Skip to content

Conversation

@Unique-Usman
Copy link
Contributor

@Unique-Usman Unique-Usman commented Jan 10, 2026

Detect Python-style numeric grouping syntax in format strings (e.g. {x:,})
and emit a clear diagnostic explaining that it is not supported in Rust.
This helps users coming from Python understand the error without exposing
the full set of valid Rust format specifiers.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 10, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 10, 2026

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@Unique-Usman
Copy link
Contributor Author

r? @estebank

@rustbot rustbot assigned estebank and unassigned SparrowLii Jan 10, 2026
@Unique-Usman
Copy link
Contributor Author

Hello as part of the ongoing effort in #145718

fn main() {
    println!("{x,}, world!",);
}

initially, the compiler gives the below error for the above

error: invalid format string: expected `}`, found `,`
 --> src/main.rs:3:14
  |
3 | println!("{x:,}");
  |           -  ^ expected `}` in format string
  |           |
  |           because of this opening brace
  |
  = note: if you intended to print `{`, you can escape it using `{{`

but after this changes, it gives a better error message suggesting the compiler understand that is a python-style numeric grouping, but it is not supported in rust.

error: invalid format string: expected `}`, found `,`
 --> ../test.rs:2:17
  |
2 |     println!("{x,}, world!",);
  |                 ^  python-style numeric grouping `,` is not supported in rust format strings in format string
  |
  = note: to print `{`, you can escape it using `{{`

error: aborting due to 1 previous error

@Unique-Usman Unique-Usman marked this pull request as draft January 10, 2026 23:30
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 10, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 11, 2026

☔ The latest upstream changes (presumably #150912) made this pull request unmergeable. Please resolve the merge conflicts.

@Unique-Usman Unique-Usman changed the title Ua/numeric rustc_parse_format: improve diagnostics for unsupported python numeric grouping Jan 11, 2026
@Unique-Usman Unique-Usman marked this pull request as ready for review January 11, 2026 04:31
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 11, 2026
@workingjubilee
Copy link
Member

workingjubilee commented Jan 11, 2026

error: invalid format string: expected `}`, found `,`
 --> ../test.rs:2:17
  |
2 |     println!("{x,}, world!",);
  |                 ^  python-style numeric grouping `,` is not supported in rust format strings in format string
  |
  = note: to print `{`, you can escape it using `{{`

error: aborting due to 1 previous error

That seems like a very weird place for a very verbose error text to be. Things in that position are usually indicative of what they are pointing at, as opposed to commenting on whether it's correct or not and how. (or at least they are much more terse when they do)

…c grouping

Detect Python-style numeric grouping syntax in format strings (e.g. `{x:,}`)
and emit a clear diagnostic explaining that it is not supported in Rust.
This helps users coming from Python understand the error without exposing
the full set of valid Rust format specifiers.

Signed-off-by: Usman Akinyemi <[email protected]>
@Unique-Usman
Copy link
Contributor Author

Thank you very much for the review @workingjubilee

@workingjubilee
Copy link
Member

I'm not aware of a digit grouping format string specifier, so it seems there is no meaningful suggestion to offer instead aside from recommending a random crate, and this seems an adequate improvement. Thank you.

@bors r+ rollup

@rust-bors rust-bors bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 12, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 12, 2026

📌 Commit 76ad528 has been approved by workingjubilee

It is now in the queue for this repository.

@rust-bors rust-bors bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 12, 2026
@Unique-Usman
Copy link
Contributor Author

Unique-Usman commented Jan 12, 2026

Thanks for the review @workingjubilee

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 12, 2026
rustc_parse_format: improve diagnostics for unsupported python numeric grouping

Detect Python-style numeric grouping syntax in format strings (e.g. `{x:,}`)
and emit a clear diagnostic explaining that it is not supported in Rust.
This helps users coming from Python understand the error without exposing
the full set of valid Rust format specifiers.
rust-bors bot added a commit that referenced this pull request Jan 12, 2026
Rollup of 5 pull requests

Successful merges:

 - #150861 (Folding/`ReErased` cleanups)
 - #150941 (rustc_parse_format: improve diagnostics for unsupported python numeric grouping)
 - #150972 (Rename EII attributes slightly (being consistent in naming things foreign items, not extern items))
 - #150980 (Use updated indexes to build reverse map for delegation generics)
 - #150986 (std: Fix size returned by UEFI tcp4 read operations)

r? @ghost
rust-bors bot pushed a commit that referenced this pull request Jan 12, 2026
Rollup of 8 pull requests

Successful merges:

 - #150861 (Folding/`ReErased` cleanups)
 - #150869 (Emit error instead of delayed bug when meeting mismatch type for const tuple)
 - #150920 (Use a hook to decouple `rustc_mir_transform` from `rustc_mir_build`)
 - #150941 (rustc_parse_format: improve diagnostics for unsupported python numeric grouping)
 - #150972 (Rename EII attributes slightly (being consistent in naming things foreign items, not extern items))
 - #150980 (Use updated indexes to build reverse map for delegation generics)
 - #150986 (std: Fix size returned by UEFI tcp4 read operations)
 - #150996 (Remove `S-waiting-on-bors` after a PR is merged)

r? @ghost
rust-bors bot pushed a commit that referenced this pull request Jan 12, 2026
Rollup of 8 pull requests

Successful merges:

 - #150861 (Folding/`ReErased` cleanups)
 - #150869 (Emit error instead of delayed bug when meeting mismatch type for const tuple)
 - #150920 (Use a hook to decouple `rustc_mir_transform` from `rustc_mir_build`)
 - #150941 (rustc_parse_format: improve diagnostics for unsupported python numeric grouping)
 - #150972 (Rename EII attributes slightly (being consistent in naming things foreign items, not extern items))
 - #150980 (Use updated indexes to build reverse map for delegation generics)
 - #150986 (std: Fix size returned by UEFI tcp4 read operations)
 - #150996 (Remove `S-waiting-on-bors` after a PR is merged)

r? @ghost
@rust-bors rust-bors bot merged commit 2caeb9f into rust-lang:main Jan 12, 2026
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 12, 2026
rust-timer added a commit that referenced this pull request Jan 12, 2026
Rollup merge of #150941 - ua/numeric, r=workingjubilee

rustc_parse_format: improve diagnostics for unsupported python numeric grouping

Detect Python-style numeric grouping syntax in format strings (e.g. `{x:,}`)
and emit a clear diagnostic explaining that it is not supported in Rust.
This helps users coming from Python understand the error without exposing
the full set of valid Rust format specifiers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants