forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#64856 - jonhoo:format-temporaries, r=sfackler
Scope format! temporaries 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
3 changed files
with
56 additions
and
27 deletions.
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
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,22 @@ | ||
// Another regression test for #64477. | ||
// | ||
// 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. | ||
// | ||
// check-pass | ||
// edition:2018 | ||
|
||
async fn foo(_: String) {} | ||
|
||
fn bar() -> impl Send { | ||
async move { | ||
foo(format!("{}:{}", 1, 2)).await; | ||
} | ||
} | ||
|
||
fn main() { | ||
let _ = bar(); | ||
} |