X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flists.rs;h=6005ae6fd259a429db2d41c8070da685655381b6;hb=cbd568083d87a90dfe5ab0e90f404454946c9f20;hp=9b65fdbd1da75c8b6044e3253afa2f04012e17f0;hpb=454a20ac011dae62c34e4d9e0590c869a6a2f017;p=rust.git diff --git a/src/lists.rs b/src/lists.rs index 9b65fdbd1da..6005ae6fd25 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -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(items: I, formatting: &ListFormatting) -> Option 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, 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, ListItemCommen ListItemCommentStyle::SameLine, ) } + } else if has_single_line_comment { + ( + Some(trimmed_pre_snippet.to_owned()), + ListItemCommentStyle::DifferentLine, + ) } else { (None, ListItemCommentStyle::None) }