Skip to content

Conversation

nilotpal-n7
Copy link

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 19, 2025

r? @lcnr

rustbot has assigned @lcnr.
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 19, 2025
@rust-log-analyzer

This comment has been minimized.

@nilotpal-n7 nilotpal-n7 requested a review from lcnr August 22, 2025 21:14
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

r=me after updating PR description + squashing commits

View changes since this review

@rustbot
Copy link
Collaborator

rustbot commented Aug 26, 2025

Some changes occurred in src/tools/cargo

cc @ehuss

@rustbot

This comment has been minimized.

@lcnr
Copy link
Contributor

lcnr commented Aug 27, 2025

You've accidentally committed changes to submodules here; see the above comment added by rustbot. This is something that can very easily happen, so don't worry about it :> still need to fix it though

@nilotpal-n7
Copy link
Author

You've accidentally committed changes to submodules here; see the above comment added by rustbot. This is something that can very easily happen, so don't worry about it :> still need to fix it though

Ah, got it 🙂.
What I did was: I synced the latest master, ran ./x build, then checked out my fix-format-issue branch (without syncing it) and made changes there before pushing. Looks like that pulled in a submodule update accidentally.
Is that the wrong way to do it? Or should I always rebase my feature branch on top of the updated master instead?

@nilotpal-n7 nilotpal-n7 force-pushed the fix-format-alignment branch 2 times, most recently from ba03ce2 to 440b820 Compare August 27, 2025 09:18
@rustbot
Copy link
Collaborator

rustbot commented Aug 27, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@nilotpal-n7 nilotpal-n7 requested a review from lcnr August 27, 2025 09:33
@lcnr
Copy link
Contributor

lcnr commented Aug 27, 2025

Please also squash this PR/merge it all into 1 commit. It's not large enough for 6 commits 😁 what tend to use is

 git rebase -i --autosquash $(git merge-base HEAD origin/master)

and then merge all relevant commits by changing them from pick to f (you can also move them around, git should provide an overview of what you can do with these commits in the relevant file)

@nilotpal-n7 nilotpal-n7 force-pushed the fix-format-alignment branch from 440b820 to fdbaaac Compare August 27, 2025 15:16
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.

4 participants