Skip to content

Commit 79d9afd

Browse files
committed
std::fmt: Fix the grammar documentation
According to the grammar documented, the format specifier `{: }` should not be legal because of the whitespace it contains. However, in reality, this is perfectly fine because the actual implementation allows spaces before the closing brace. Fixes #71088. Also, the exact meaning of most of the terminal symbols was not specified, for example the meaning of `identifier`.
1 parent afd80a2 commit 79d9afd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

library/alloc/src/fmt.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@
310310
//! ```text
311311
//! format_string := text [ maybe_format text ] *
312312
//! maybe_format := '{' '{' | '}' '}' | format
313-
//! format := '{' [ argument ] [ ':' format_spec ] '}'
313+
//! format := '{' [ argument ] [ ':' format_spec ] [ ws ] * '}'
314314
//! argument := integer | identifier
315315
//!
316316
//! format_spec := [[fill]align][sign]['#']['0'][width]['.' precision]type
@@ -323,7 +323,12 @@
323323
//! count := parameter | integer
324324
//! parameter := argument '$'
325325
//! ```
326-
//! In the above grammar, `text` must not contain any `'{'` or `'}'` characters.
326+
//! In the above grammar,
327+
//! - `text` must not contain any `'{'` or `'}'` characters,
328+
//! - `ws` is any character for which [`char::is_whitespace`] returns `true`, has no semantic
329+
//! meaning and is completely optional,
330+
//! - `integer` is a decimal integer that may contain leading zeroes and
331+
//! - `identifier` is an `IDENTIFIER_OR_KEYWORD` (not an `IDENTIFIER`) as defined by the [Rust language reference](https://doc.rust-lang.org/reference/identifiers.html).
327332
//!
328333
//! # Formatting traits
329334
//!

0 commit comments

Comments
 (0)