about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-01-31 07:00:42 +0100
committerGitHub <noreply@github.com>2022-01-31 07:00:42 +0100
commitc1e2948c21398d98ada51f27bd9fa3ada439e03d (patch)
tree776941fc8495bc55eef89511bec16d34b9a3c431 /src/test
parent8fd2ff57fa936f1fb24afe1f452e8d2ef9b485d6 (diff)
parent858d6a071199b30ea95c744895f61f93ad188ffb (diff)
Rollup merge of #93461 - dtolnay:fmtyield, r=davidtwco
Accommodate yield points in the format_args expansion

Fixes #93274.

For the case `println!("{} {:?}", "", async {}.await)` in the issue, the expansion before:

```rust
::std::io::_print(
    ::core::fmt::Arguments::new_v1(
        &["", " ", "\n"],
        &[
            ::core::fmt::ArgumentV1::new(&"", ::core::fmt::Display::fmt),
            ::core::fmt::ArgumentV1::new(&async {}.await, ::core::fmt::Debug::fmt),
        ],
    ),
);
```

After:

```rust
::std::io::_print(
    ::core::fmt::Arguments::new_v1(
        &["", " ", "\n"],
        &match (&"", &async {}.await) {
            _args => [
                ::core::fmt::ArgumentV1::new(_args.0, ::core::fmt::Display::fmt),
                ::core::fmt::ArgumentV1::new(_args.1, ::core::fmt::Debug::fmt),
            ],
        },
    ),
);
```
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/fmt/format-with-yield-point.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/ui/fmt/format-with-yield-point.rs b/src/test/ui/fmt/format-with-yield-point.rs
new file mode 100644
index 00000000000..e484074cc9a
--- /dev/null
+++ b/src/test/ui/fmt/format-with-yield-point.rs
@@ -0,0 +1,33 @@
+// check-pass
+// edition:2021
+
+macro_rules! m {
+    () => {
+        async {}.await
+    };
+}
+
+async fn with_await() {
+    println!("{} {:?}", "", async {}.await);
+}
+
+async fn with_macro_call_expr() {
+    println!("{} {:?}", "", m!());
+}
+
+async fn with_macro_call_stmt_semi() {
+    println!("{} {:?}", "", { m!(); });
+}
+
+async fn with_macro_call_stmt_braced() {
+    println!("{} {:?}", "", { m!{} });
+}
+
+fn assert_send(_: impl Send) {}
+
+fn main() {
+    assert_send(with_await());
+    assert_send(with_macro_call_expr());
+    assert_send(with_macro_call_stmt_semi());
+    assert_send(with_macro_call_stmt_braced());
+}