use crate::spanned::Spanned;
use crate::utils::{
contains_skip, extra_offset, first_line_width, inner_attributes, last_line_extendable, mk_sp,
- ptr_vec_to_ref_vec, semicolon_for_expr, trimmed_last_line_width,
+ ptr_vec_to_ref_vec, semicolon_for_expr, trimmed_last_line_width, unicode_str_width,
};
/// A simple wrapper type against `ast::Arm`. Used inside `write_list()`.
match expr.node {
ast::ExprKind::Block(ref block, _)
if !is_unsafe_block(block)
+ && !context.inside_macro()
&& is_simple_block(block, Some(&expr.attrs), context.source_map) =>
{
Some(&*block)
}
let indent_str = shape.indent.to_string_with_newline(context.config);
- let (body_prefix, body_suffix) = if context.config.match_arm_blocks() {
- let comma = if context.config.match_block_trailing_comma() {
- ","
- } else {
- ""
- };
- let semicolon = if context.config.version() == Version::One {
- ""
- } else {
- if semicolon_for_expr(context, body) {
- ";"
+ let (body_prefix, body_suffix) =
+ if context.config.match_arm_blocks() && !context.inside_macro() {
+ let comma = if context.config.match_block_trailing_comma() {
+ ","
} else {
""
- }
+ };
+ let semicolon = if context.config.version() == Version::One {
+ ""
+ } else {
+ if semicolon_for_expr(context, body) {
+ ";"
+ } else {
+ ""
+ }
+ };
+ ("{", format!("{}{}}}{}", semicolon, indent_str, comma))
+ } else {
+ ("", String::from(","))
};
- ("{", format!("{}{}}}{}", semicolon, indent_str, comma))
- } else {
- ("", String::from(","))
- };
let block_sep = match context.config.control_brace_style() {
ControlBraceStyle::AlwaysNextLine => format!("{}{}", alt_block_sep, body_prefix),
match rewrite {
Some(ref body_str)
- if is_block || (!body_str.contains('\n') && body_str.len() <= body_shape.width) =>
+ if is_block
+ || (!body_str.contains('\n')
+ && unicode_str_width(body_str) <= body_shape.width) =>
{
return combine_orig_body(body_str);
}
next_line_body_shape.width,
);
match (orig_body, next_line_body) {
- (Some(ref orig_str), Some(ref next_line_str)) if orig_str == next_line_str => {
- combine_orig_body(orig_str)
- }
(Some(ref orig_str), Some(ref next_line_str))
if prefer_next_line(orig_str, next_line_str, RhsTactics::Default) =>
{
| ast::ExprKind::Box(ref expr)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Unary(_, ref expr)
+ | ast::ExprKind::Index(ref expr, _)
| ast::ExprKind::Cast(ref expr, _) => can_flatten_block_around_this(expr),
_ => false,
}