Skip to content

Commit 8064a24

Browse files
committed
Auto merge of rust-lang#147449 - matthiaskrgr:rollup-njyi5yr, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#145943 (stdlib docs: document lifetime extension for `format_args!`'s arguments) - rust-lang#147243 (cmse: disallow `impl Trait` in `cmse-nonsecure-entry` return types) - rust-lang#147402 ([rustdoc] Don't serialize & deserialize data that doesn't go OTW) - rust-lang#147418 (Fix target list of `link_section`) - rust-lang#147429 (Print tip for human error format in runtest) - rust-lang#147441 (Fix comments error for Provenance impls) - rust-lang#147442 (c-variadic: fix thir-print for `...` without a pattern) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 72f6c77 + bda1247 commit 8064a24

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

core/src/macros/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,9 @@ pub(crate) mod builtin {
951951
/// format string in `format_args!`.
952952
///
953953
/// ```rust
954-
/// let debug = format!("{:?}", format_args!("{} foo {:?}", 1, 2));
955-
/// let display = format!("{}", format_args!("{} foo {:?}", 1, 2));
954+
/// let args = format_args!("{} foo {:?}", 1, 2);
955+
/// let debug = format!("{args:?}");
956+
/// let display = format!("{args}");
956957
/// assert_eq!("1 foo 2", display);
957958
/// assert_eq!(display, debug);
958959
/// ```
@@ -976,13 +977,17 @@ pub(crate) mod builtin {
976977
/// assert_eq!(s, format!("hello {}", "world"));
977978
/// ```
978979
///
979-
/// # Lifetime limitation
980+
/// # Argument lifetimes
980981
///
981982
/// Except when no formatting arguments are used,
982-
/// the produced `fmt::Arguments` value borrows temporary values,
983-
/// which means it can only be used within the same expression
984-
/// and cannot be stored for later use.
985-
/// This is a known limitation, see [#92698](https://github.com/rust-lang/rust/issues/92698).
983+
/// the produced `fmt::Arguments` value borrows temporary values.
984+
/// To allow it to be stored for later use, the arguments' lifetimes, as well as those of
985+
/// temporaries they borrow, may be [extended] when `format_args!` appears in the initializer
986+
/// expression of a `let` statement. The syntactic rules used to determine when temporaries'
987+
/// lifetimes are extended are documented in the [Reference].
988+
///
989+
/// [extended]: ../reference/destructors.html#temporary-lifetime-extension
990+
/// [Reference]: ../reference/destructors.html#extending-based-on-expressions
986991
#[stable(feature = "rust1", since = "1.0.0")]
987992
#[rustc_diagnostic_item = "format_args_macro"]
988993
#[allow_internal_unsafe]

0 commit comments

Comments
 (0)