forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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#64477 for details.
- Loading branch information
Showing
2 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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(); | ||
} |