Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,21 @@ fn rewrite_closure_fn_decl(
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<(String, usize)> {
let is_async = if asyncness.is_async() { "async " } else { "" };
let mover = if capture == ast::CaptureBy::Value {
"move "
let immovable = if movability == ast::Movability::Static {
"static "
} else {
""
};
let immovable = if movability == ast::Movability::Static {
"static "
let is_async = if asyncness.is_async() { "async " } else { "" };
let mover = if capture == ast::CaptureBy::Value {
"move "
} 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 = |
Expand Down Expand Up @@ -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') {
Expand Down
16 changes: 16 additions & 0 deletions tests/source/async_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,20 @@ fn baz() {
Ok(())
},
);

spawn(
a,
static async || {
action();
Ok(())
},
);

spawn(
a,
static async move || {
action();
Ok(())
},
);
}
10 changes: 10 additions & 0 deletions tests/target/async_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ fn baz() {
action();
Ok(())
});

spawn(a, static async || {
action();
Ok(())
});

spawn(a, static async move || {
action();
Ok(())
});
}