Fix static async closure qualifier order

This commit is contained in:
David Tolnay 2021-12-23 14:23:51 -08:00 committed by Caleb Cartwright
parent 7b8303d479
commit 0b2fd9b132
3 changed files with 33 additions and 7 deletions

View File

@ -236,21 +236,21 @@ fn rewrite_closure_fn_decl(
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<(String, usize)> {
let immovable = if movability == ast::Movability::Static {
"static "
} else {
""
};
let is_async = if asyncness.is_async() { "async " } else { "" };
let mover = if capture == ast::CaptureBy::Value {
"move "
} else {
""
};
let immovable = if movability == ast::Movability::Static {
"static "
} else {
""
};
// 4 = "|| {".len(), which is overconservative when the closure consists of
// a single expression.
let nested_shape = shape
.shrink_left(is_async.len() + mover.len() + immovable.len())?
.shrink_left(immovable.len() + is_async.len() + mover.len())?
.sub_width(4)?;
// 1 = |
@ -288,7 +288,7 @@ fn rewrite_closure_fn_decl(
.tactic(tactic)
.preserve_newline(true);
let list_str = write_list(&item_vec, &fmt)?;
let mut prefix = format!("{}{}{}|{}|", is_async, immovable, mover, list_str);
let mut prefix = format!("{}{}{}|{}|", immovable, is_async, mover, list_str);
if !ret_str.is_empty() {
if prefix.contains('\n') {

View File

@ -32,4 +32,20 @@ fn baz() {
Ok(())
},
);
spawn(
a,
static async || {
action();
Ok(())
},
);
spawn(
a,
static async move || {
action();
Ok(())
},
);
}

View File

@ -22,4 +22,14 @@ fn baz() {
action();
Ok(())
});
spawn(a, static async || {
action();
Ok(())
});
spawn(a, static async move || {
action();
Ok(())
});
}