diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-12-07 11:05:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-07 11:05:06 +0100 |
| commit | b2dcfddb24df78ec660b498ddf780550ba052119 (patch) | |
| tree | 68734e75c6c9c691b0aee3a678eac6a9bc7899f8 | |
| parent | 1c2fba65406e1d901194ec4c2c3162ba10e45f5b (diff) | |
| parent | 33c29a3ad36621bf812fd8af0adceb16188f3624 (diff) | |
| download | rust-b2dcfddb24df78ec660b498ddf780550ba052119.tar.gz rust-b2dcfddb24df78ec660b498ddf780550ba052119.zip | |
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 {}"</code>
**After:** `"async {}"`
<br>
In this function:
https://github.com/rust-lang/rust/blob/65c55bf931a55e6b1e5ed14ad8623814a7386424/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.
https://github.com/rust-lang/rust/blob/65c55bf931a55e6b1e5ed14ad8623814a7386424/compiler/rustc_ast_pretty/src/pprust/state.rs#L2640-L2645
https://github.com/rust-lang/rust/blob/65c55bf931a55e6b1e5ed14ad8623814a7386424/compiler/rustc_ast_pretty/src/helpers.rs#L34-L37
https://github.com/rust-lang/rust/blob/65c55bf931a55e6b1e5ed14ad8623814a7386424/compiler/rustc_ast_pretty/src/helpers.rs#L5-L8
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state.rs | 1 | ||||
| -rw-r--r-- | src/test/pretty/async.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/async-await/issues/issue-54752-async-block.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/async-await/issues/issue-54752-async-block.stderr | 8 |
4 files changed, 14 insertions, 6 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 95d45f07e9d..921ac785e81 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -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); 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 +} 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 |
