Skip to content

Fix format string grammar in docs and improve alignment error message #144023 #145512

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

nilotpal-n7
Copy link

@nilotpal-n7 nilotpal-n7 commented Aug 16, 2025

This PR improves error messages and documentation for format strings involving alignment and formatting traits.

Highlights:

  • Clearer error messages for invalid alignment specifiers (e.g., {0:#X>18}), showing the expected <, ^, or > and a working example:

    println!("{0:>#18X}", value);

  • Updated UI test format-alignment-hash.rs to reflect the improved error output.

  • Documentation clarification: ensures examples correctly show how width, alignment, and traits like x, X, # combine.

Motivation:
Previously, using # with alignment and width produced confusing errors. This PR guides users on the correct syntax and provides actionable examples.

Testing:

  • Built the compiler (./x build)
  • Blessed and ran UI tests (./x. test src/test/ui/fmt/format-alignment-hash.rs --bless)
  • Verified full test suite passes (./x test)

Issue: #144023

@rustbot
Copy link
Collaborator

rustbot commented Aug 16, 2025

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

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 16, 2025
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

nilotpal-n7 and others added 2 commits August 17, 2025 23:10
Co-authored-by: León Orell Valerian Liehr <[email protected]>
Co-authored-by: Lieselotte <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants