Skip to content

Commit 37683d7

Browse files
authored
Unrolled build for #151013
Rollup merge of #151013 - ehuss:fmt-clarification, r=joboet Add some clarifications and fixes for fmt syntax This tries to clarify a few things regarding fmt syntax: - The comment on `Parser::word` seems to be wrong, as that underscore-prefixed words are just fine. This was changed in #66847. - I struggled to follow the description of the width argument. It referred to a "second argument", but I don't know what second argument it is referring to (which is the first?). Either way, I rewrote the paragraph to try to be a little more explicit, and to use shorter sentences. - The description of the precision argument wasn't really clear about the distinction of an Nth argument and a named argument. I added a sentence to try to emphasize the difference. - `IDENTIFIER_OR_KEYWORD` was changed recently in rust-lang/reference#2049 to include bare `_`. But fmt named arguments are not allowed to be a bare `_`.
2 parents 466ea4e + 9a5aa90 commit 37683d7

File tree

2 files changed

+11
-6
lines changed
  • compiler/rustc_parse_format/src
  • library/alloc/src

2 files changed

+11
-6
lines changed

compiler/rustc_parse_format/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ impl<'input> Parser<'input> {
758758
}
759759

760760
/// Parses a word starting at the current position. A word is the same as a
761-
/// Rust identifier, except that it can't start with `_` character.
761+
/// Rust identifier or keyword, except that it can't be a bare `_` character.
762762
fn word(&mut self) -> &'input str {
763763
let index = self.input_vec_index;
764764
match self.peek() {

library/alloc/src/fmt.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@
136136
//! padding specified by fill/alignment will be used to take up the required
137137
//! space (see below).
138138
//!
139-
//! The value for the width can also be provided as a [`usize`] in the list of
140-
//! parameters by adding a postfix `$`, indicating that the second argument is
141-
//! a [`usize`] specifying the width.
139+
//! The width can also be provided dynamically by referencing another argument
140+
//! with a `$` suffix. Use `{:N$}` to reference the Nth positional argument
141+
//! (where N is an integer), or `{:name$}` to reference a named argument. The
142+
//! referenced argument must be of type [`usize`].
142143
//!
143144
//! Referring to an argument with the dollar syntax does not affect the "next
144145
//! argument" counter, so it's usually a good idea to refer to arguments by
@@ -236,7 +237,8 @@
236237
//!
237238
//! 2. An integer or name followed by dollar sign `.N$`:
238239
//!
239-
//! use format *argument* `N` (which must be a `usize`) as the precision.
240+
//! use the value of format *argument* `N` (which must be a `usize`) as the precision.
241+
//! An integer refers to a positional argument, and a name refers to a named argument.
240242
//!
241243
//! 3. An asterisk `.*`:
242244
//!
@@ -363,7 +365,10 @@
363365
//! - `ws` is any character for which [`char::is_whitespace`] returns `true`, has no semantic
364366
//! meaning and is completely optional,
365367
//! - `integer` is a decimal integer that may contain leading zeroes and must fit into an `usize` and
366-
//! - `identifier` is an `IDENTIFIER_OR_KEYWORD` (not an `IDENTIFIER`) as defined by the [Rust language reference](https://doc.rust-lang.org/reference/identifiers.html).
368+
//! - `identifier` is an `IDENTIFIER_OR_KEYWORD` (not an `IDENTIFIER`) as
369+
//! defined by the [Rust language
370+
//! reference](https://doc.rust-lang.org/reference/identifiers.html), except
371+
//! for a bare `_`.
367372
//!
368373
//! # Formatting traits
369374
//!

0 commit comments

Comments
 (0)