From a9f14c18fa1fe455aa9ea3efb74335653d51a884 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 5 Dec 2021 11:21:24 -0800 Subject: [PATCH 1/2] Add pretty printer test for async blocks Currently fails with: ---- [pretty] pretty/async.rs stdout ---- error: pretty-printed source does not match expected source expected: ------------------------------------------ // pp-exact // pretty-compare-only // edition:2021 async fn f() { let first = async { 1 }; let second = async move { 2 }; join(first, second).await } ------------------------------------------ actual: ------------------------------------------ // pp-exact // pretty-compare-only // edition:2021 async fn f() { let first = async { 1 }; let second = async move { 2 }; join(first, second).await } ------------------------------------------ diff: ------------------------------------------ 3 // edition:2021 4 5 async fn f() { - let first = async { 1 }; - let second = async move { 2 }; + let first = async { 1 }; + let second = async move { 2 }; 8 join(first, second).await 9 } 10 --- src/test/pretty/async.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/test/pretty/async.rs diff --git a/src/test/pretty/async.rs b/src/test/pretty/async.rs new file mode 100644 index 00000000000..573e79bffd7 --- /dev/null +++ b/src/test/pretty/async.rs @@ -0,0 +1,9 @@ +// pp-exact +// pretty-compare-only +// edition:2021 + +async fn f() { + let first = async { 1 }; + let second = async move { 2 }; + join(first, second).await +} From 33c29a3ad36621bf812fd8af0adceb16188f3624 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 5 Dec 2021 10:53:21 -0800 Subject: [PATCH 2/2] Pretty print async block without redundant space --- compiler/rustc_ast_pretty/src/pprust/state.rs | 1 - src/test/ui/async-await/issues/issue-54752-async-block.rs | 2 +- .../ui/async-await/issues/issue-54752-async-block.stderr | 8 ++++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 593dca1b405..096406ad0e7 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -2068,7 +2068,6 @@ impl<'a> State<'a> { ast::ExprKind::Async(capture_clause, _, ref blk) => { self.word_nbsp("async"); self.print_capture_clause(capture_clause); - self.s.space(); // cbox/ibox in analogy to the `ExprKind::Block` arm above self.cbox(INDENT_UNIT); self.ibox(0); diff --git a/src/test/ui/async-await/issues/issue-54752-async-block.rs b/src/test/ui/async-await/issues/issue-54752-async-block.rs index c2840d7386f..a8165ae6c32 100644 --- a/src/test/ui/async-await/issues/issue-54752-async-block.rs +++ b/src/test/ui/async-await/issues/issue-54752-async-block.rs @@ -3,5 +3,5 @@ // edition:2018 // pp-exact -fn main() { let _a = (async { }); } +fn main() { let _a = (async { }); } //~^ WARNING unnecessary parentheses around assigned value diff --git a/src/test/ui/async-await/issues/issue-54752-async-block.stderr b/src/test/ui/async-await/issues/issue-54752-async-block.stderr index 0aea56ddb70..e3ed0b53356 100644 --- a/src/test/ui/async-await/issues/issue-54752-async-block.stderr +++ b/src/test/ui/async-await/issues/issue-54752-async-block.stderr @@ -1,14 +1,14 @@ warning: unnecessary parentheses around assigned value --> $DIR/issue-54752-async-block.rs:6:22 | -LL | fn main() { let _a = (async { }); } - | ^ ^ +LL | fn main() { let _a = (async { }); } + | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | -LL - fn main() { let _a = (async { }); } -LL + fn main() { let _a = async { }; } +LL - fn main() { let _a = (async { }); } +LL + fn main() { let _a = async { }; } | warning: 1 warning emitted