This places the temporaries that `format!` generates to refer to its
arguments (through `&dyn Trait`) in a short-lived scope surrounding just
the invocation of `format!`. This enables `format!` to be used in
generators without the temporaries preventing the generator from being
`Send` (due to `dyn Trait` not being `Sync`).
See rust-lang/rust#64477 for details.
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! format {
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! format {
- ($($arg:tt)*) => ($crate::fmt::format($crate::__export::format_args!($($arg)*)))
+ ($($arg:tt)*) => {{
+ let res = $crate::fmt::format($crate::__export::format_args!($($arg)*));
+ res
+ }}
--- /dev/null
+// In the past, the code generated by `format!` produced temporaries in the surrounding scope that
+// borrowed the arguments through `&dyn Trait`. These temporaries do not implement `Send`, which
+// meant that when `format!` was used in an async block, the resulting generator was not `Send`.
+// See https://github.com/rust-lang/rust/issues/64477#issuecomment-534669068 for details
+// and https://github.com/rust-lang/rust/issues/64477#issuecomment-531882958 for an example.
+async fn foo(_: String) {}
+
+fn bar() -> impl Send {
+ async move {
+ foo(format!("{}:{}", 1, 2)).await;
+ }
+}
+
+fn main() {
+ let _ = bar();
+}