]> git.lizzy.rs Git - rust.git/commitdiff
Add trailing comma when using mixed layout with block indent
authorSeiichi Uchida <seiichi.uchida@dena.com>
Thu, 5 Apr 2018 04:27:42 +0000 (13:27 +0900)
committerSeiichi Uchida <seiichi.uchida@dena.com>
Thu, 5 Apr 2018 04:27:42 +0000 (13:27 +0900)
src/lists.rs

index 05b1a7ce2963be91e8575f935ecf49fb3b741877..d0e9863f2f45df5383357747b4c2befc11a97f2a 100644 (file)
@@ -172,11 +172,10 @@ pub fn definitive_tactic<I, T>(
 
     let limit = match tactic {
         _ if pre_line_comments => return DefinitiveListTactic::Vertical,
-        ListTactic::Mixed => return DefinitiveListTactic::Mixed,
         ListTactic::Horizontal => return DefinitiveListTactic::Horizontal,
         ListTactic::Vertical => return DefinitiveListTactic::Vertical,
         ListTactic::LimitedHorizontalVertical(limit) => ::std::cmp::min(width, limit),
-        ListTactic::HorizontalVertical => width,
+        ListTactic::Mixed | ListTactic::HorizontalVertical => width,
     };
 
     let (sep_count, total_width) = calculate_width(items.clone());
@@ -188,7 +187,10 @@ pub fn definitive_tactic<I, T>(
     {
         DefinitiveListTactic::Horizontal
     } else {
-        DefinitiveListTactic::Vertical
+        match tactic {
+            ListTactic::Mixed => DefinitiveListTactic::Mixed,
+            _ => DefinitiveListTactic::Vertical,
+        }
     }
 }
 
@@ -276,8 +278,7 @@ pub fn write_list<I, T>(items: I, formatting: &ListFormatting) -> Option<String>
 
                 if last && formatting.ends_with_newline {
                     match formatting.trailing_separator {
-                        SeparatorTactic::Always => separate = true,
-                        SeparatorTactic::Vertical if result.contains('\n') => separate = true,
+                        SeparatorTactic::Always | SeparatorTactic::Vertical => separate = true,
                         _ => (),
                     }
                 }