Skip to content

Conversation

nilotpal-n7
Copy link
Contributor

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
Contributor 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
@nilotpal-n7
Copy link
Contributor Author

@rustbot ready

@lcnr
Copy link
Contributor

lcnr commented Aug 31, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Aug 31, 2025

📌 Commit fdbaaac has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 31, 2025
bors added a commit that referenced this pull request Aug 31, 2025
Rollup of 4 pull requests

Successful merges:

 - #144443 (Make target pointer width in target json an integer)
 - #145174 (Ensure consistent drop for panicking drop in hint::select_unpredictable)
 - #145592 (Fix format string grammar in docs and improve alignment error message for #144023)
 - #145931 (Clarify that align_offset overaligns)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e5f96e3 into rust-lang:master Aug 31, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 31, 2025
rust-timer added a commit that referenced this pull request Aug 31, 2025
Rollup merge of #145592 - nilotpal-n7:fix-format-alignment, r=lcnr

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

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
github-actions bot pushed a commit to rust-lang/compiler-builtins that referenced this pull request Sep 1, 2025
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#144443 (Make target pointer width in target json an integer)
 - rust-lang/rust#145174 (Ensure consistent drop for panicking drop in hint::select_unpredictable)
 - rust-lang/rust#145592 (Fix format string grammar in docs and improve alignment error message for rust-lang/rust#144023)
 - rust-lang/rust#145931 (Clarify that align_offset overaligns)

r? `@ghost`
`@rustbot` modify labels: rollup
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Sep 1, 2025
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#144443 (Make target pointer width in target json an integer)
 - rust-lang/rust#145174 (Ensure consistent drop for panicking drop in hint::select_unpredictable)
 - rust-lang/rust#145592 (Fix format string grammar in docs and improve alignment error message for rust-lang/rust#144023)
 - rust-lang/rust#145931 (Clarify that align_offset overaligns)

r? `@ghost`
`@rustbot` modify labels: rollup
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Sep 9, 2025
…r=lcnr

Fix format string grammar in docs and improve alignment error message for rust-lang#144023

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: rust-lang#144023
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. 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.

5 participants