Skip to content

Conversation

@Unique-Usman
Copy link
Contributor

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

Detect the {ident?} pattern where ? is immediately followed by } and emit a clearer diagnostic explaining that : is required for Debug formatting. This avoids falling back to a generic “invalid format string” error and adds a targeted UI test for the case.

@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 7, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 7, 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 7, 2026
@Unique-Usman
Copy link
Contributor Author

This pr serves as an efforts toward issues 145718.

Following up with our conversation @estebank, I was working on the issue but, I saw this and I thought on working on it while i can keep working on other part of the issue.

If you have a

fn main() {
    let x = 4;
    println!("{x?}, world!",);
}

Someone will get this error

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

error: aborting due to 1 previous error

But, I believe, missing colon : is a better diagnostic here.

My proposed improvement was to sort of combine the current diagnostic error with the missing colon. After this pr, this is what will be output which I believe is a better diagnostic.

error: invalid format string: expected `}`, found `?` or missing `:` before `?`
 --> ../testing.rs:3:17
  |
3 |     println!("{x?}, world!",);
  |                 ^ expected `}` in format string or missing `:` before `?` in format string
  |
  = note: to print `{`, you can escape it using `{{`, to format with `Debug`, use `:?`

error: aborting due to 1 previous error

I am also thinking having only missing colon is okay here, what do you think ? We can also improve the above diagnostic message here.

@estebank estebank changed the title rustc_parse_format: improve error for missing : before ? in forma… rustc_parse_format: improve error for missing : before ? in format args Jan 7, 2026
@Unique-Usman
Copy link
Contributor Author

Unique-Usman commented Jan 7, 2026

Thanks for the review @estebank, made the requested change.

…t args

Detect the `{ident?}` pattern where `?` is immediately followed by `}` and emit
a clearer diagnostic explaining that `:` is required for Debug formatting.
This avoids falling back to a generic “invalid format string” error and adds
a targeted UI test for the case.

Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
@estebank
Copy link
Contributor

estebank commented Jan 8, 2026

@bors r+

@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 8, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 8, 2026

📌 Commit b0e65da has been approved by estebank

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 8, 2026
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 9, 2026
rustc_parse_format: improve error for missing `:` before `?` in format args

Detect the `{ident?}` pattern where `?` is immediately followed by `}` and emit a clearer diagnostic explaining that `:` is required for Debug formatting. This avoids falling back to a generic “invalid format string” error and adds a targeted UI test for the case.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 9, 2026
rustc_parse_format: improve error for missing `:` before `?` in format args

Detect the `{ident?}` pattern where `?` is immediately followed by `}` and emit a clearer diagnostic explaining that `:` is required for Debug formatting. This avoids falling back to a generic “invalid format string” error and adds a targeted UI test for the case.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 9, 2026
rustc_parse_format: improve error for missing `:` before `?` in format args

Detect the `{ident?}` pattern where `?` is immediately followed by `}` and emit a clearer diagnostic explaining that `:` is required for Debug formatting. This avoids falling back to a generic “invalid format string” error and adds a targeted UI test for the case.
rust-bors bot added a commit that referenced this pull request Jan 10, 2026
Rollup of 11 pull requests

Successful merges:

 - #150269 (Remove inactive nvptx maintainer)
 - #150713 (mgca: Type-check fields of struct expr const args)
 - #150765 (rustc_parse_format: improve error for missing `:` before `?` in format args)
 - #150847 (Fix broken documentation links to SipHash)
 - #150867 (rustdoc_json: Remove one call to `std::mem::take` in `after_krate`)
 - #150872 (Fix some loop block coercion diagnostics)
 - #150874 (Ignore `rustc-src-gpl` in fast try builds)
 - #150875 (Refactor artifact keep mode in bootstrap)
 - #150876 (Mention that `rustc_codegen_gcc` is a subtree in `rustc-dev-guide`)
 - #150882 (Supress unused_parens lint for guard patterns)
 - #150884 (Update bors email in CI postprocessing step)

Failed merges:

 - #150869 (Emit error instead of delayed bug when meeting mismatch type for const tuple)

r? @ghost
rust-bors bot added a commit that referenced this pull request Jan 10, 2026
Rollup of 11 pull requests

Successful merges:

 - #150269 (Remove inactive nvptx maintainer)
 - #150713 (mgca: Type-check fields of struct expr const args)
 - #150765 (rustc_parse_format: improve error for missing `:` before `?` in format args)
 - #150847 (Fix broken documentation links to SipHash)
 - #150867 (rustdoc_json: Remove one call to `std::mem::take` in `after_krate`)
 - #150872 (Fix some loop block coercion diagnostics)
 - #150874 (Ignore `rustc-src-gpl` in fast try builds)
 - #150875 (Refactor artifact keep mode in bootstrap)
 - #150876 (Mention that `rustc_codegen_gcc` is a subtree in `rustc-dev-guide`)
 - #150882 (Supress unused_parens lint for guard patterns)
 - #150884 (Update bors email in CI postprocessing step)

Failed merges:

 - #150869 (Emit error instead of delayed bug when meeting mismatch type for const tuple)

r? @ghost
@rust-bors rust-bors bot merged commit a8d66d4 into rust-lang:main Jan 11, 2026
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 11, 2026
rust-timer added a commit that referenced this pull request Jan 11, 2026
Rollup merge of #150765 - ua/missing-colon, r=estebank

rustc_parse_format: improve error for missing `:` before `?` in format args

Detect the `{ident?}` pattern where `?` is immediately followed by `}` and emit a clearer diagnostic explaining that `:` is required for Debug formatting. This avoids falling back to a generic “invalid format string” error and adds a targeted UI test for the case.
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jan 12, 2026
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#150269 (Remove inactive nvptx maintainer)
 - rust-lang/rust#150713 (mgca: Type-check fields of struct expr const args)
 - rust-lang/rust#150765 (rustc_parse_format: improve error for missing `:` before `?` in format args)
 - rust-lang/rust#150847 (Fix broken documentation links to SipHash)
 - rust-lang/rust#150867 (rustdoc_json: Remove one call to `std::mem::take` in `after_krate`)
 - rust-lang/rust#150872 (Fix some loop block coercion diagnostics)
 - rust-lang/rust#150874 (Ignore `rustc-src-gpl` in fast try builds)
 - rust-lang/rust#150875 (Refactor artifact keep mode in bootstrap)
 - rust-lang/rust#150876 (Mention that `rustc_codegen_gcc` is a subtree in `rustc-dev-guide`)
 - rust-lang/rust#150882 (Supress unused_parens lint for guard patterns)
 - rust-lang/rust#150884 (Update bors email in CI postprocessing step)

Failed merges:

 - rust-lang/rust#150869 (Emit error instead of delayed bug when meeting mismatch type for const tuple)

r? @ghost
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.

4 participants