Skip to content
Open
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
26 changes: 26 additions & 0 deletions src/tools/rustfmt/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ pub(crate) fn format_expr(
ast::ExprKind::Yeet(Some(ref expr)) => {
rewrite_unary_prefix(context, "do yeet ", &**expr, shape)
}
ast::ExprKind::CilkSync => Some("cilk_sync".to_owned()),
ast::ExprKind::AddrOf(borrow_kind, mutability, ref expr) => {
rewrite_expr_addrof(context, borrow_kind, mutability, expr, shape)
}
Expand Down Expand Up @@ -397,6 +398,31 @@ pub(crate) fn format_expr(
))
}
}
// TODO(jhilton): add a test for cilk_spawn once we have the rest of parsing working!
ast::ExprKind::CilkSpawn(ref block) => {
if let rw @ Some(_) = rewrite_single_line_block(
context,
"cilk_spawn",
block,
Some(&expr.attrs),
None,
shape,
) {
rw
} else {
let budget = shape.width.saturating_sub(6);
Some(format!(
"cilk_spawn {}",
rewrite_block(
block,
Some(&expr.attrs),
None,
context,
Shape::legacy(budget, shape.indent)
)?
))
}
}
ast::ExprKind::Underscore => Some("_".to_owned()),
ast::ExprKind::FormatArgs(..)
| ast::ExprKind::IncludedBytes(..)
Expand Down
4 changes: 3 additions & 1 deletion src/tools/rustfmt/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
| ast::ExprKind::Loop(..)
| ast::ExprKind::ForLoop { .. }
| ast::ExprKind::TryBlock(..)
| ast::ExprKind::CilkSpawn(..)
| ast::ExprKind::Match(..) => repr.contains('\n'),
ast::ExprKind::Paren(ref expr)
| ast::ExprKind::Binary(_, _, ref expr)
Expand Down Expand Up @@ -512,7 +513,8 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
| ast::ExprKind::Tup(..)
| ast::ExprKind::Type(..)
| ast::ExprKind::Yield(None)
| ast::ExprKind::Underscore => false,
| ast::ExprKind::Underscore
| ast::ExprKind::CilkSync => false,
}
}

Expand Down