id: ast::NodeId::root(),
kind: ast::StmtKind::Expr(ptr::P(body.clone())),
span: body.span,
- tokens: None,
}],
id: ast::NodeId::root(),
rules: ast::BlockCheckMode::Default,
.first()
.map(|attr| attr.span.to(body.span))
.unwrap_or(body.span),
+ could_be_bare_literal: false,
};
let block = crate::expr::rewrite_block_with_visitor(
context,
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 = |
.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') {
// We force to use block for the body of the closure for certain kinds of expressions.
if is_block_closure_forced(context, body) {
- return rewrite_closure_with_block(body, &prefix, context, body_shape).and_then(
+ return rewrite_closure_with_block(body, &prefix, context, body_shape).map(
|body_str| {
match fn_decl.output {
ast::FnRetTy::Default(..) if body_str.lines().count() <= 7 => {
// closure. However, if the closure has a return type, then we must
// keep the blocks.
match rewrite_closure_expr(body, &prefix, context, shape) {
- Some(ref single_line_body_str)
+ Some(single_line_body_str)
if !single_line_body_str.contains('\n') =>
{
- Some(single_line_body_str.clone())
+ single_line_body_str
}
- _ => Some(body_str),
+ _ => body_str,
}
}
- _ => Some(body_str),
+ _ => body_str,
}
},
);
pub(crate) fn args_have_many_closure(args: &[OverflowableItem<'_>]) -> bool {
args.iter()
.filter_map(OverflowableItem::to_expr)
- .filter(|expr| match expr.kind {
- ast::ExprKind::Closure(..) => true,
- _ => false,
- })
+ .filter(|expr| matches!(expr.kind, ast::ExprKind::Closure(..)))
.count()
> 1
}