]> git.lizzy.rs Git - rust.git/blobdiff - src/overflow.rs
Change `print_diff` to output the correct line number.
[rust.git] / src / overflow.rs
index 54e594d814f8a210d4beac2f518ca3093f3b3778..674eb14b677b3435faa03a77f49c3860d066480f 100644 (file)
 
 use config::lists::*;
 use syntax::ast;
-use syntax::codemap::Span;
 use syntax::parse::token::DelimToken;
+use syntax::source_map::Span;
 
 use closures;
-use codemap::SpanUtils;
 use expr::{is_every_expr_simple, is_method_call, is_nested_call, maybe_get_args_offset, ToExpr};
 use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator};
 use rewrite::{Rewrite, RewriteContext};
 use shape::Shape;
+use source_map::SpanUtils;
 use spanned::Spanned;
 use utils::{count_newlines, extra_offset, first_line_width, last_line_width, mk_sp};
 
@@ -223,7 +223,7 @@ fn try_overflow_last_item(&self, list_items: &mut Vec<ListItem>) -> DefinitiveLi
         // 1 = "("
         let combine_arg_with_callee = self.items.len() == 1
             && self.items[0].to_expr().is_some()
-            && self.ident.len() + 1 <= self.context.config.tab_spaces();
+            && self.ident.len() < self.context.config.tab_spaces();
         let overflow_last = combine_arg_with_callee || can_be_overflowed(self.context, self.items);
 
         // Replace the last item with its first line to see if it fits with
@@ -291,7 +291,7 @@ fn try_overflow_last_item(&self, list_items: &mut Vec<ListItem>) -> DefinitiveLi
             (true, DefinitiveListTactic::Horizontal, placeholder @ Some(..)) => {
                 list_items[self.items.len() - 1].item = placeholder;
             }
-            _ if self.items.len() >= 1 => {
+            _ if !self.items.is_empty() => {
                 list_items[self.items.len() - 1].item = self
                     .items
                     .last()
@@ -363,32 +363,27 @@ fn rewrite_items(&self) -> Option<(bool, String)> {
         // indentation. If its first line fits on one line with the other arguments,
         // we format the function arguments horizontally.
         let tactic = self.try_overflow_last_item(&mut list_items);
-
-        let fmt = ListFormatting {
-            tactic,
-            separator: ",",
-            trailing_separator: if let Some(tactic) = self.force_separator_tactic {
-                tactic
-            } else if !self.context.use_block_indent() {
-                SeparatorTactic::Never
-            } else if tactic == DefinitiveListTactic::Mixed {
-                // We are using mixed layout because everything did not fit within a single line.
-                SeparatorTactic::Always
-            } else {
-                self.context.config.trailing_comma()
-            },
-            separator_place: SeparatorPlace::Back,
-            shape: self.nested_shape,
-            ends_with_newline: match tactic {
-                DefinitiveListTactic::Vertical | DefinitiveListTactic::Mixed => {
-                    self.context.use_block_indent()
-                }
-                _ => false,
-            },
-            preserve_newline: false,
-            nested: false,
-            config: self.context.config,
+        let trailing_separator = if let Some(tactic) = self.force_separator_tactic {
+            tactic
+        } else if !self.context.use_block_indent() {
+            SeparatorTactic::Never
+        } else if tactic == DefinitiveListTactic::Mixed {
+            // We are using mixed layout because everything did not fit within a single line.
+            SeparatorTactic::Always
+        } else {
+            self.context.config.trailing_comma()
         };
+        let ends_with_newline = match tactic {
+            DefinitiveListTactic::Vertical | DefinitiveListTactic::Mixed => {
+                self.context.use_block_indent()
+            }
+            _ => false,
+        };
+
+        let fmt = ListFormatting::new(self.nested_shape, self.context.config)
+            .tactic(tactic)
+            .trailing_separator(trailing_separator)
+            .ends_with_newline(ends_with_newline);
 
         write_list(&list_items, &fmt)
             .map(|items_str| (tactic == DefinitiveListTactic::Horizontal, items_str))