Skip to content

Commit

Permalink
Self format rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Apr 18, 2024
1 parent 3126770 commit 922e8ba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
30 changes: 13 additions & 17 deletions src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,26 +391,22 @@ pub(crate) fn rewrite_last_closure(

// 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).map(
|body_str| {
match fn_decl.output {
ast::FnRetTy::Default(..) if body_str.lines().count() <= 7 => {
// If the expression can fit in a single line, we need not force block
// closure. However, if the closure has a return type, then we must
// keep the blocks.
match rewrite_closure_expr(body, &prefix, context, shape) {
Some(single_line_body_str)
if !single_line_body_str.contains('\n') =>
{
single_line_body_str
}
_ => body_str,
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 => {
// If the expression can fit in a single line, we need not force block
// closure. However, if the closure has a return type, then we must
// keep the blocks.
match rewrite_closure_expr(body, &prefix, context, shape) {
Some(single_line_body_str) if !single_line_body_str.contains('\n') => {
single_line_body_str
}
_ => body_str,
}
_ => body_str,
}
},
);
_ => body_str,
}
});
}

// When overflowing the closure which consists of a single control flow expression,
Expand Down
3 changes: 2 additions & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ pub(crate) fn format_expr(
if contains_skip(&*expr.attrs) {
return Some(context.snippet(expr.span()).to_owned());
}
let shape = if context.config.version() == Version::One && expr_type == ExprType::Statement
let shape = if context.config.version() == Version::One
&& expr_type == ExprType::Statement
&& semicolon_for_expr_extra_hacky_double_counted_spacing(context, expr)
{
shape.sub_width(1)?
Expand Down
7 changes: 1 addition & 6 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,7 @@ fn rewrite_macro_inner(
} = match parse_macro_args(context, ts, style, is_forced_bracket) {
Some(args) => args,
None => {
return return_macro_parse_failure_fallback(
context,
shape.indent,
position,
mac.span(),
);
return return_macro_parse_failure_fallback(context, shape.indent, position, mac.span());
}
};

Expand Down

0 comments on commit 922e8ba

Please sign in to comment.