Skip to content

Commit 5790c99

Browse files
authored
Rollup merge of rust-lang#80601 - steffahn:improve_format_string_grammar, r=m-ou-se
Improve grammar in documentation of format strings The docs previously were * using some weird `<` and `>` around some nonterminals * _correct me if these **did** have any meaning_ * using of a (not explicitly defined) `text` nonterminal that didn’t explicitly disallow productions containing `'{'` or `'}'` * incorrect in not allowing for `x?` and `X?` productions of `type` * unnecessarily ambiguous, both * allowing `type` to be `''`, and * using an optional `[type]` * using inconsistent underscore/hyphenation style between `format_string` and `format_spec` vs `maybe-format` _Rendered:_ ![Screenshot_20210101_230901](https://user-images.githubusercontent.com/3986214/103447038-69d7a180-4c86-11eb-8fa0-0a6160a7ff7a.png) _(current docs: https://doc.rust-lang.org/nightly/std/fmt/#syntax)_ ```@rustbot``` modify labels: T-doc
2 parents 7f91371 + ccdd7dd commit 5790c99

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

alloc/src/fmt.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -282,21 +282,22 @@
282282
//! `%`. The actual grammar for the formatting syntax is:
283283
//!
284284
//! ```text
285-
//! format_string := <text> [ maybe-format <text> ] *
286-
//! maybe-format := '{' '{' | '}' '}' | <format>
285+
//! format_string := text [ maybe_format text ] *
286+
//! maybe_format := '{' '{' | '}' '}' | format
287287
//! format := '{' [ argument ] [ ':' format_spec ] '}'
288288
//! argument := integer | identifier
289289
//!
290-
//! format_spec := [[fill]align][sign]['#']['0'][width]['.' precision][type]
290+
//! format_spec := [[fill]align][sign]['#']['0'][width]['.' precision]type
291291
//! fill := character
292292
//! align := '<' | '^' | '>'
293293
//! sign := '+' | '-'
294294
//! width := count
295295
//! precision := count | '*'
296-
//! type := identifier | '?' | ''
296+
//! type := '' | '?' | 'x?' | 'X?' | identifier
297297
//! count := parameter | integer
298298
//! parameter := argument '$'
299299
//! ```
300+
//! In the above grammar, `text` may not contain any `'{'` or `'}'` characters.
300301
//!
301302
//! # Formatting traits
302303
//!

0 commit comments

Comments
 (0)