Remove newlines between list elements for expressions
This commit is contained in:
parent
8b5831b501
commit
261865ecc9
@ -567,6 +567,7 @@ pub fn rewrite_array<'a, I>(
|
||||
},
|
||||
shape: nested_shape,
|
||||
ends_with_newline: ends_with_newline,
|
||||
preserve_newline: false,
|
||||
config: context.config,
|
||||
};
|
||||
let list_str = try_opt!(write_list(&items, &fmt));
|
||||
@ -642,6 +643,7 @@ fn rewrite_closure_fn_decl(
|
||||
trailing_separator: SeparatorTactic::Never,
|
||||
shape: arg_shape,
|
||||
ends_with_newline: false,
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
let list_str = try_opt!(write_list(&item_vec, &fmt));
|
||||
@ -1696,6 +1698,7 @@ fn rewrite_match_pattern(
|
||||
trailing_separator: SeparatorTactic::Never,
|
||||
shape: pat_shape,
|
||||
ends_with_newline: false,
|
||||
preserve_newline: false,
|
||||
config: context.config,
|
||||
};
|
||||
let pats_str = try_opt!(write_list(&items, &fmt));
|
||||
@ -2188,6 +2191,7 @@ fn rewrite_call_args<'a, T>(
|
||||
},
|
||||
shape: shape,
|
||||
ends_with_newline: context.use_block_indent() && tactic == DefinitiveListTactic::Vertical,
|
||||
preserve_newline: false,
|
||||
config: context.config,
|
||||
};
|
||||
|
||||
@ -2783,6 +2787,7 @@ fn rewrite_tuple_in_visual_indent_style<'a, T>(
|
||||
trailing_separator: SeparatorTactic::Never,
|
||||
shape: shape,
|
||||
ends_with_newline: false,
|
||||
preserve_newline: false,
|
||||
config: context.config,
|
||||
};
|
||||
let list_str = try_opt!(write_list(&item_vec, &fmt));
|
||||
|
@ -478,6 +478,7 @@ fn rewrite_use_list(
|
||||
},
|
||||
shape: nested_shape,
|
||||
ends_with_newline: ends_with_newline,
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
let list_str = try_opt!(write_list(&items[first_index..], &fmt));
|
||||
|
@ -477,6 +477,7 @@ fn format_variant_list(
|
||||
trailing_separator: self.config.trailing_comma(),
|
||||
shape: shape,
|
||||
ends_with_newline: true,
|
||||
preserve_newline: true,
|
||||
config: self.config,
|
||||
};
|
||||
|
||||
@ -2252,6 +2253,7 @@ enum ArgumentKind<'a> {
|
||||
},
|
||||
shape: Shape::legacy(budget, indent),
|
||||
ends_with_newline: tactic.ends_with_newline(context.config.fn_args_layout()),
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
|
||||
@ -2425,6 +2427,7 @@ pub fn format_generics_item_list<I>(
|
||||
},
|
||||
shape: shape,
|
||||
ends_with_newline: tactic.ends_with_newline(context.config.generics_indent()),
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
|
||||
@ -2538,6 +2541,7 @@ fn rewrite_where_clause_rfc_style(
|
||||
trailing_separator: comma_tactic,
|
||||
shape: clause_shape,
|
||||
ends_with_newline: true,
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
let preds_str = try_opt!(write_list(&items.collect::<Vec<_>>(), &fmt));
|
||||
@ -2639,6 +2643,7 @@ fn rewrite_where_clause(
|
||||
trailing_separator: comma_tactic,
|
||||
shape: Shape::legacy(budget, offset),
|
||||
ends_with_newline: tactic.ends_with_newline(context.config.where_pred_indent()),
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
let preds_str = try_opt!(write_list(&item_vec, &fmt));
|
||||
|
@ -65,6 +65,8 @@ pub struct ListFormatting<'a> {
|
||||
// Non-expressions, e.g. items, will have a new line at the end of the list.
|
||||
// Important for comment styles.
|
||||
pub ends_with_newline: bool,
|
||||
// Remove newlines between list elements for expressions.
|
||||
pub preserve_newline: bool,
|
||||
pub config: &'a Config,
|
||||
}
|
||||
|
||||
@ -342,7 +344,9 @@ pub fn write_list<I, T>(items: I, formatting: &ListFormatting) -> Option<String>
|
||||
item_max_width = None;
|
||||
}
|
||||
|
||||
if !last && tactic == DefinitiveListTactic::Vertical && item.new_lines {
|
||||
if formatting.preserve_newline && !last && tactic == DefinitiveListTactic::Vertical &&
|
||||
item.new_lines
|
||||
{
|
||||
item_max_width = None;
|
||||
result.push('\n');
|
||||
}
|
||||
@ -675,6 +679,7 @@ pub fn struct_lit_formatting<'a>(
|
||||
},
|
||||
shape: shape,
|
||||
ends_with_newline: ends_with_newline,
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
}
|
||||
}
|
||||
|
@ -361,6 +361,7 @@ enum ArgumentKind<T>
|
||||
},
|
||||
shape: list_shape,
|
||||
ends_with_newline: tactic.ends_with_newline(context.config.fn_call_style()),
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
|
||||
|
@ -229,6 +229,7 @@ fn rewrite_aligned_items_inner<T: AlignedItem>(
|
||||
trailing_separator: context.config.trailing_comma(),
|
||||
shape: item_shape,
|
||||
ends_with_newline: true,
|
||||
preserve_newline: true,
|
||||
config: context.config,
|
||||
};
|
||||
write_list(&items, &fmt)
|
||||
|
@ -820,6 +820,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
|
||||
trailing_separator: SeparatorTactic::Never,
|
||||
shape: item_shape,
|
||||
ends_with_newline: false,
|
||||
preserve_newline: false,
|
||||
config: context.config,
|
||||
};
|
||||
format!("{}({})", name, try_opt!(write_list(&item_vec, &fmt)))
|
||||
|
Loading…
Reference in New Issue
Block a user