Skip to content

Commit b2dcfdd

Browse files
authored
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: 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
2 parents 1c2fba6 + 33c29a3 commit b2dcfdd

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,6 @@ impl<'a> State<'a> {
20772077
ast::ExprKind::Async(capture_clause, _, ref blk) => {
20782078
self.word_nbsp("async");
20792079
self.print_capture_clause(capture_clause);
2080-
self.s.space();
20812080
// cbox/ibox in analogy to the `ExprKind::Block` arm above
20822081
self.cbox(INDENT_UNIT);
20832082
self.ibox(0);

src/test/pretty/async.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// pp-exact
2+
// pretty-compare-only
3+
// edition:2021
4+
5+
async fn f() {
6+
let first = async { 1 };
7+
let second = async move { 2 };
8+
join(first, second).await
9+
}

src/test/ui/async-await/issues/issue-54752-async-block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
// edition:2018
44
// pp-exact
55

6-
fn main() { let _a = (async { }); }
6+
fn main() { let _a = (async { }); }
77
//~^ WARNING unnecessary parentheses around assigned value

src/test/ui/async-await/issues/issue-54752-async-block.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
warning: unnecessary parentheses around assigned value
22
--> $DIR/issue-54752-async-block.rs:6:22
33
|
4-
LL | fn main() { let _a = (async { }); }
5-
| ^ ^
4+
LL | fn main() { let _a = (async { }); }
5+
| ^ ^
66
|
77
= note: `#[warn(unused_parens)]` on by default
88
help: remove these parentheses
99
|
10-
LL - fn main() { let _a = (async { }); }
11-
LL + fn main() { let _a = async { }; }
10+
LL - fn main() { let _a = (async { }); }
11+
LL + fn main() { let _a = async { }; }
1212
|
1313

1414
warning: 1 warning emitted

0 commit comments

Comments
 (0)