Fix up write_list() to handle Mixed tactic
@@ -207,10 +207,18 @@ impl SeparatorPlace {
*self == SeparatorPlace::Back
}
- pub fn from_tactic(default: SeparatorPlace, tactic: DefinitiveListTactic) -> SeparatorPlace {
+ pub fn from_tactic(
+ default: SeparatorPlace,
+ tactic: DefinitiveListTactic,
+ sep: &str,
+ ) -> SeparatorPlace {
match tactic {
DefinitiveListTactic::Vertical => default,
- _ => SeparatorPlace::Back,
+ _ => if sep == "," {
+ SeparatorPlace::Back
+ } else {
+ default
+ },
}
}
}
@@ -269,7 +277,8 @@ where
let cloned_items = items.clone();
let mut iter = items.into_iter().enumerate().peekable();
let mut item_max_width: Option<usize> = None;
- let mut sep_place = SeparatorPlace::from_tactic(formatting.separator_place, tactic);
+ let sep_place =
+ SeparatorPlace::from_tactic(formatting.separator_place, tactic, formatting.separator);
let mut line_len = 0;
let indent_str = &formatting.shape.indent.to_string(formatting.config);
@@ -278,7 +287,10 @@ where
let inner_item = item.item.as_ref()?;
let first = i == 0;
let last = iter.peek().is_none();
- let mut separate = !last || trailing_separator;
+ let mut separate = match sep_place {
+ SeparatorPlace::Front => !first,
+ SeparatorPlace::Back => !last || trailing_separator,
+ };
let item_sep_len = if separate { sep_len } else { 0 };
// Item string may be multi-line. Its length (used for block comment alignment)
@@ -316,9 +328,6 @@ where
trailing_separator = true;
}
}
- sep_place = formatting.separator_place;
- } else {
- sep_place = SeparatorPlace::Back;
}
if line_len > 0 {
