Rollup merge of #91562 - dtolnay:asyncspace, r=Mark-Simulacrum

Pretty print async block without redundant space

**Repro:**

```rust
macro_rules! m {
    ($e:expr) => { stringify!($e) };
}
fn main() {
    println!("{:?}", m!(async {}));
}
```

**Before:** <code>"async&nbsp;&nbsp;{}"</code>
**After:** `"async {}"`

<br>

In this function:

65c55bf931/compiler/rustc_ast_pretty/src/pprust/state.rs (L2049-L2051)

the `print_capture_clause` and `word_nbsp`/`word_space` calls already put a space after the `async` and `move` keywords being printed. The extra `self.s.space()` call removed by this PR resulted in the redundant double space.

65c55bf931/compiler/rustc_ast_pretty/src/pprust/state.rs (L2640-L2645)

65c55bf931/compiler/rustc_ast_pretty/src/helpers.rs (L34-L37)

65c55bf931/compiler/rustc_ast_pretty/src/helpers.rs (L5-L8)
This commit is contained in:
Matthias Krüger 2021-12-07 11:05:06 +01:00 committed by GitHub
commit b2dcfddb24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 6 deletions

View File

@ -2077,7 +2077,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);

9
src/test/pretty/async.rs Normal file
View File

@ -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
}

View File

@ -3,5 +3,5 @@
// edition:2018
// pp-exact
fn main() { let _a = (async { }); }
fn main() { let _a = (async { }); }
//~^ WARNING unnecessary parentheses around assigned value

View File

@ -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