]> git.lizzy.rs Git - rust.git/blobdiff - src/vertical.rs
Merge pull request #3035 from topecongiro/issue-3006
[rust.git] / src / vertical.rs
index 58422d782ac9ab9a9781bed0aec306e7de108bb8..3f5339201063fb183e90f48157943a3af4876186 100644 (file)
 
 use config::lists::*;
 use syntax::ast;
-use syntax::codemap::{BytePos, Span};
+use syntax::source_map::{BytePos, Span};
 
-use codemap::SpanUtils;
 use comment::{combine_strs_with_missing_comments, contains_comment};
 use expr::rewrite_field;
 use items::{rewrite_struct_field, rewrite_struct_field_prefix};
 use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
 use rewrite::{Rewrite, RewriteContext};
 use shape::{Indent, Shape};
+use source_map::SpanUtils;
 use spanned::Spanned;
 use utils::{contains_skip, is_attributes_extendable, mk_sp, rewrite_ident};
 
@@ -126,7 +126,7 @@ pub fn rewrite_with_alignment<T: AlignedItem>(
     } else {
         ("", fields.len() - 1)
     };
-    let init = &fields[0..group_index + 1];
+    let init = &fields[0..=group_index];
     let rest = &fields[group_index + 1..];
     let init_last_pos = if rest.is_empty() {
         span.hi()
@@ -173,11 +173,14 @@ pub fn rewrite_with_alignment<T: AlignedItem>(
         let rest_span = mk_sp(init_last_pos, span.hi());
         let rest_str = rewrite_with_alignment(rest, context, shape, rest_span, one_line_width)?;
         Some(
-            result + spaces + "\n"
+            result
+                + spaces
+                + "\n"
                 + &shape
                     .indent
                     .block_indent(context.config)
-                    .to_string(context.config) + &rest_str,
+                    .to_string(context.config)
+                + &rest_str,
         )
     }
 }
@@ -197,14 +200,12 @@ fn struct_field_prefix_max_min_width<T: AlignedItem>(
                     Some(field_str.len())
                 }
             })
-        })
-        .fold(Some((0, ::std::usize::MAX)), |acc, len| match (acc, len) {
+        }).fold(Some((0, ::std::usize::MAX)), |acc, len| match (acc, len) {
             (Some((max_len, min_len)), Some(len)) => {
                 Some((cmp::max(max_len, len), cmp::min(min_len, len)))
             }
             _ => None,
-        })
-        .unwrap_or((0, 0))
+        }).unwrap_or((0, 0))
 }
 
 fn rewrite_aligned_items_inner<T: AlignedItem>(
@@ -244,17 +245,10 @@ fn rewrite_aligned_items_inner<T: AlignedItem>(
         one_line_width,
     );
 
-    let fmt = ListFormatting {
-        tactic,
-        separator: ",",
-        trailing_separator: context.config.trailing_comma(),
-        separator_place: SeparatorPlace::Back,
-        shape: item_shape,
-        ends_with_newline: true,
-        preserve_newline: true,
-        nested: false,
-        config: context.config,
-    };
+    let fmt = ListFormatting::new(item_shape, context.config)
+        .tactic(tactic)
+        .trailing_separator(context.config.trailing_comma())
+        .preserve_newline(true);
     write_list(&items, &fmt)
 }