mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
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: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:
commit
b2dcfddb24
@ -2077,7 +2077,6 @@ impl<'a> State<'a> {
|
|||||||
ast::ExprKind::Async(capture_clause, _, ref blk) => {
|
ast::ExprKind::Async(capture_clause, _, ref blk) => {
|
||||||
self.word_nbsp("async");
|
self.word_nbsp("async");
|
||||||
self.print_capture_clause(capture_clause);
|
self.print_capture_clause(capture_clause);
|
||||||
self.s.space();
|
|
||||||
// cbox/ibox in analogy to the `ExprKind::Block` arm above
|
// cbox/ibox in analogy to the `ExprKind::Block` arm above
|
||||||
self.cbox(INDENT_UNIT);
|
self.cbox(INDENT_UNIT);
|
||||||
self.ibox(0);
|
self.ibox(0);
|
||||||
|
9
src/test/pretty/async.rs
Normal file
9
src/test/pretty/async.rs
Normal 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
|
||||||
|
}
|
@ -3,5 +3,5 @@
|
|||||||
// edition:2018
|
// edition:2018
|
||||||
// pp-exact
|
// pp-exact
|
||||||
|
|
||||||
fn main() { let _a = (async { }); }
|
fn main() { let _a = (async { }); }
|
||||||
//~^ WARNING unnecessary parentheses around assigned value
|
//~^ WARNING unnecessary parentheses around assigned value
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
warning: unnecessary parentheses around assigned value
|
warning: unnecessary parentheses around assigned value
|
||||||
--> $DIR/issue-54752-async-block.rs:6:22
|
--> $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
|
= note: `#[warn(unused_parens)]` on by default
|
||||||
help: remove these parentheses
|
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
|
warning: 1 warning emitted
|
||||||
|
Loading…
Reference in New Issue
Block a user