]> git.lizzy.rs Git - rust.git/blobdiff - src/reorder.rs
rewrite_string: retain blank lines that are trailing
[rust.git] / src / reorder.rs
index 5947b4ae87ffd4b6835e5755df19ef5df733be9d..f990e68656590a601c07d82a0db0cbea6237b641 100644 (file)
 
 // FIXME(#2455): Reorder trait items.
 
-use config::{lists::*, Config};
-use syntax::{ast, attr, codemap::Span};
+use config::Config;
+use syntax::{ast, attr, source_map::Span};
 
 use attr::filter_inline_attrs;
-use codemap::LineRangeUtils;
 use comment::combine_strs_with_missing_comments;
 use imports::{merge_use_trees, UseTree};
 use items::{is_mod_decl, rewrite_extern_crate, rewrite_mod};
 use lists::{itemize_list, write_list, ListFormatting, ListItem};
 use rewrite::{Rewrite, RewriteContext};
 use shape::Shape;
+use source_map::LineRangeUtils;
 use spanned::Spanned;
 use utils::mk_sp;
 use visitor::FmtVisitor;
@@ -69,18 +69,7 @@ fn wrap_reorderable_items(
     list_items: &[ListItem],
     shape: Shape,
 ) -> Option<String> {
-    let fmt = ListFormatting {
-        tactic: DefinitiveListTactic::Vertical,
-        separator: "",
-        trailing_separator: SeparatorTactic::Never,
-        separator_place: SeparatorPlace::Back,
-        shape,
-        ends_with_newline: true,
-        preserve_newline: false,
-        nested: false,
-        config: context.config,
-    };
-
+    let fmt = ListFormatting::new(shape, context.config).separator("");
     write_list(list_items, &fmt)
 }
 
@@ -205,12 +194,12 @@ fn from(item: &ast::Item) -> Self {
         }
     }
 
-    fn is_same_item_kind(&self, item: &ast::Item) -> bool {
-        ReorderableItemKind::from(item) == *self
+    fn is_same_item_kind(self, item: &ast::Item) -> bool {
+        ReorderableItemKind::from(item) == self
     }
 
-    fn is_reorderable(&self, config: &Config) -> bool {
-        match *self {
+    fn is_reorderable(self, config: &Config) -> bool {
+        match self {
             ReorderableItemKind::ExternCrate => config.reorder_imports(),
             ReorderableItemKind::Mod => config.reorder_modules(),
             ReorderableItemKind::Use => config.reorder_imports(),
@@ -218,8 +207,8 @@ fn is_reorderable(&self, config: &Config) -> bool {
         }
     }
 
-    fn in_group(&self) -> bool {
-        match *self {
+    fn in_group(self) -> bool {
+        match self {
             ReorderableItemKind::ExternCrate
             | ReorderableItemKind::Mod
             | ReorderableItemKind::Use => true,
@@ -238,13 +227,13 @@ fn walk_reorderable_items(
         item_kind: ReorderableItemKind,
         in_group: bool,
     ) -> usize {
-        let mut last = self.codemap.lookup_line_range(items[0].span());
+        let mut last = self.source_map.lookup_line_range(items[0].span());
         let item_length = items
             .iter()
             .take_while(|ppi| {
                 item_kind.is_same_item_kind(&***ppi)
                     && (!in_group || {
-                        let current = self.codemap.lookup_line_range(ppi.span());
+                        let current = self.source_map.lookup_line_range(ppi.span());
                         let in_same_group = current.lo < last.hi + 2;
                         last = current;
                         in_same_group