diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-08-31 13:40:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-31 13:40:35 +0200 |
| commit | e5f96e3b4370286ec972e4bb7a26566e8e98e1ea (patch) | |
| tree | 95907700bd486a90bbbb54d346a86b26fe28f715 /compiler/rustc_parse_format | |
| parent | 59a645ac2592582dbe41cd9747b6e9c0eb706bb7 (diff) | |
| parent | fdbaaac245673d8dbf7bcc21ebedc833693434f6 (diff) | |
| download | rust-e5f96e3b4370286ec972e4bb7a26566e8e98e1ea.tar.gz rust-e5f96e3b4370286ec972e4bb7a26566e8e98e1ea.zip | |
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: rust-lang/rust#144023
Diffstat (limited to 'compiler/rustc_parse_format')
| -rw-r--r-- | compiler/rustc_parse_format/src/lib.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/rustc_parse_format/src/lib.rs b/compiler/rustc_parse_format/src/lib.rs index 8e4da7923fc..5cda0b813d2 100644 --- a/compiler/rustc_parse_format/src/lib.rs +++ b/compiler/rustc_parse_format/src/lib.rs @@ -858,7 +858,9 @@ impl<'input> Parser<'input> { self.errors.insert( 0, ParseError { - description: "expected format parameter to occur after `:`".to_owned(), + description: + "expected alignment specifier after `:` in format string; example: `{:>?}`" + .to_owned(), note: None, label: format!("expected `{}` to occur after `:`", alignment), span: range, |
