Skip to content

Commit 8fc1a72

Browse files
authored
Rollup merge of #105836 - evanj:fmt-doc-use-variables, r=Mark-Simulacrum
std::fmt: Use args directly in example code The lint "clippy::uninlined_format_args" recommends inline variables in format strings. Fix two places in the docs that do not do this. I noticed this because I copy/pasted one example in to my project, then noticed this lint error. This fixes: ``` error: variables can be used directly in the `format!` string --> src/main.rs:30:22 | 30 | let string = format!("{:.*}", decimals, magnitude); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: variables can be used directly in the `format!` string --> src/main.rs:39:2 | 39 | write!(&mut io::stdout(), "{}", args).unwrap(); ```
2 parents cf08eda + ab2151c commit 8fc1a72

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

library/alloc/src/fmt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@
419419
//! // documentation for details, and the function `pad` can be used
420420
//! // to pad strings.
421421
//! let decimals = f.precision().unwrap_or(3);
422-
//! let string = format!("{:.*}", decimals, magnitude);
422+
//! let string = format!("{magnitude:.decimals$}");
423423
//! f.pad_integral(true, "", &string)
424424
//! }
425425
//! }
@@ -518,7 +518,7 @@
518518
//! write!(&mut some_writer, "{}", format_args!("print with a {}", "macro"));
519519
//!
520520
//! fn my_fmt_fn(args: fmt::Arguments) {
521-
//! write!(&mut io::stdout(), "{}", args);
521+
//! write!(&mut io::stdout(), "{args}");
522522
//! }
523523
//! my_fmt_fn(format_args!(", or a {} too", "function"));
524524
//! ```

0 commit comments

Comments
 (0)