You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: library/core/src/macros/mod.rs
+12-7Lines changed: 12 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -951,8 +951,9 @@ pub(crate) mod builtin {
951
951
/// format string in `format_args!`.
952
952
///
953
953
/// ```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}");
956
957
/// assert_eq!("1 foo 2", display);
957
958
/// assert_eq!(display, debug);
958
959
/// ```
@@ -976,13 +977,17 @@ pub(crate) mod builtin {
976
977
/// assert_eq!(s, format!("hello {}", "world"));
977
978
/// ```
978
979
///
979
-
/// # Lifetime limitation
980
+
/// # Argument lifetimes
980
981
///
981
982
/// 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].
0 commit comments