span,
context.config.width_heuristics().fn_call_width,
if context.inside_macro {
- span_ends_with_comma(context, span)
+ if span_ends_with_comma(context, span) {
+ Some(SeparatorTactic::Always)
+ } else {
+ Some(SeparatorTactic::Never)
+ }
} else {
- false
+ None
},
)
}
debug!("rewrite_tuple {:?}", shape);
if context.use_block_indent() {
// We use the same rule as function calls for rewriting tuples.
- let force_trailing_comma = if context.inside_macro {
- span_ends_with_comma(context, span)
+ let force_tactic = if context.inside_macro {
+ if span_ends_with_comma(context, span) {
+ Some(SeparatorTactic::Always)
+ } else {
+ Some(SeparatorTactic::Never)
+ }
} else {
- items.len() == 1
+ if items.len() == 1 {
+ Some(SeparatorTactic::Always)
+ } else {
+ None
+ }
};
overflow::rewrite_with_parens(
context,
shape,
span,
context.config.width_heuristics().fn_call_width,
- force_trailing_comma,
+ force_tactic,
)
} else {
rewrite_tuple_in_visual_indent_style(context, items, span, shape)
shape,
span,
context.config.width_heuristics().fn_call_width,
- false,
+ None,
)?;
}
shape,
mac.span,
context.config.width_heuristics().fn_call_width,
- trailing_comma,
+ if trailing_comma {
+ Some(SeparatorTactic::Always)
+ } else {
+ Some(SeparatorTactic::Never)
+ },
).map(|rw| match position {
MacroPosition::Item => format!("{};", rw),
_ => rw,
shape: Shape,
span: Span,
item_max_width: usize,
- force_trailing_comma: bool,
+ force_separator_tactic: Option<SeparatorTactic>,
) -> Option<String>
where
T: Rewrite + ToExpr + Spanned,
"(",
")",
item_max_width,
- force_trailing_comma,
+ force_separator_tactic,
).rewrite(shape)
}
"<",
">",
context.config.max_width(),
- false,
+ None,
).rewrite(shape)
}
span: Span,
item_max_width: usize,
one_line_width: usize,
- force_trailing_comma: bool,
+ force_separator_tactic: Option<SeparatorTactic>,
}
impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> {
prefix: &'static str,
suffix: &'static str,
item_max_width: usize,
- force_trailing_comma: bool,
+ force_separator_tactic: Option<SeparatorTactic>,
) -> Context<'a, T> {
// 2 = `( `, 1 = `(`
let paren_overhead = if context.config.spaces_within_parens_and_brackets() {
suffix,
item_max_width,
one_line_width,
- force_trailing_comma,
+ force_separator_tactic,
}
}
let fmt = ListFormatting {
tactic,
separator: ",",
- trailing_separator: if self.force_trailing_comma {
- SeparatorTactic::Always
- } else if self.context.inside_macro || !self.context.use_block_indent() {
+ trailing_separator: if let Some(tactic) = self.force_separator_tactic {
+ tactic
+ } else if !self.context.use_block_indent() {
SeparatorTactic::Never
} else {
self.context.config.trailing_comma()
shape,
span,
context.config.max_width(),
- add_comma,
+ if add_comma {
+ Some(SeparatorTactic::Always)
+ } else {
+ None
+ },
)
}