]> git.lizzy.rs Git - rust.git/blobdiff - src/lists.rs
Fixup formatting
[rust.git] / src / lists.rs
index 49548cc26a318ffb8055f8cb4e6c791e31e3cd8d..6005ae6fd259a429db2d41c8070da685655381b6 100644 (file)
@@ -14,7 +14,7 @@
 use std::iter::Peekable;
 
 use config::lists::*;
-use syntax::codemap::BytePos;
+use syntax::source_map::BytePos;
 
 use comment::{find_comment_end, rewrite_comment, FindUncommented};
 use config::{Config, IndentStyle};
@@ -146,10 +146,12 @@ pub fn inner_as_ref(&self) -> &str {
     }
 
     pub fn is_different_group(&self) -> bool {
-        self.inner_as_ref().contains('\n') || self.pre_comment.is_some() || self
-            .post_comment
-            .as_ref()
-            .map_or(false, |s| s.contains('\n'))
+        self.inner_as_ref().contains('\n')
+            || self.pre_comment.is_some()
+            || self
+                .post_comment
+                .as_ref()
+                .map_or(false, |s| s.contains('\n'))
     }
 
     pub fn is_multiline(&self) -> bool {
@@ -209,8 +211,8 @@ pub enum Separator {
 }
 
 impl Separator {
-    pub fn len(&self) -> usize {
-        match *self {
+    pub fn len(self) -> usize {
+        match self {
             // 2 = `, `
             Separator::Comma => 2,
             // 3 = ` | `
@@ -475,7 +477,7 @@ pub fn write_list<I, T>(items: I, formatting: &ListFormatting) -> Option<String>
                     formatted_comment = rewrite_post_comment(&mut item_max_width)?;
                     comment_alignment = post_comment_alignment(item_max_width, inner_item.len());
                 }
-                for _ in 0..(comment_alignment + 1) {
+                for _ in 0..=comment_alignment {
                     result.push(' ');
                 }
                 // An additional space for the missing trailing separator.
@@ -566,14 +568,9 @@ pub struct ListItems<'a, I, F1, F2, F3>
 
 pub fn extract_pre_comment(pre_snippet: &str) -> (Option<String>, ListItemCommentStyle) {
     let trimmed_pre_snippet = pre_snippet.trim();
+    let has_block_comment = trimmed_pre_snippet.ends_with("*/");
     let has_single_line_comment = trimmed_pre_snippet.starts_with("//");
-    let has_block_comment = trimmed_pre_snippet.starts_with("/*");
-    if has_single_line_comment {
-        (
-            Some(trimmed_pre_snippet.to_owned()),
-            ListItemCommentStyle::DifferentLine,
-        )
-    } else if has_block_comment {
+    if has_block_comment {
         let comment_end = pre_snippet.chars().rev().position(|c| c == '/').unwrap();
         if pre_snippet
             .chars()
@@ -591,6 +588,11 @@ pub fn extract_pre_comment(pre_snippet: &str) -> (Option<String>, ListItemCommen
                 ListItemCommentStyle::SameLine,
             )
         }
+    } else if has_single_line_comment {
+        (
+            Some(trimmed_pre_snippet.to_owned()),
+            ListItemCommentStyle::DifferentLine,
+        )
     } else {
         (None, ListItemCommentStyle::None)
     }