From 367a874d04abfb2269ff1ea1974f06640546b7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 19 Dec 2020 13:42:55 +0100 Subject: [PATCH] address review comments and fix new clippy findings introduced since I made this PR --- src/formatting/attr.rs | 2 +- src/formatting/comment.rs | 4 ++-- src/formatting/vertical.rs | 19 +++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/formatting/attr.rs b/src/formatting/attr.rs index 172946e1c84..dd312e49cb2 100644 --- a/src/formatting/attr.rs +++ b/src/formatting/attr.rs @@ -187,7 +187,7 @@ fn format_derive( } else if let SeparatorTactic::Always = context.config.trailing_comma() { // Retain the trailing comma. result.push_str(&item_str); - } else if item_str.ends_with(",") { + } else if item_str.ends_with(',') { // Remove the trailing comma. result.push_str(&item_str[..item_str.len() - 1]); } else { diff --git a/src/formatting/comment.rs b/src/formatting/comment.rs index d617a79e85a..23d7700056c 100644 --- a/src/formatting/comment.rs +++ b/src/formatting/comment.rs @@ -1704,8 +1704,8 @@ impl<'a> Iterator for CommentReducer<'a> { fn remove_comment_header(comment: &str) -> &str { if comment.starts_with("///") || comment.starts_with("//!") { &comment[3..] - } else if comment.starts_with("//") { - &comment[2..] + } else if let Some(stripped) = comment.strip_prefix("//") { + &stripped } else if (comment.starts_with("/**") && !comment.starts_with("/**/")) || comment.starts_with("/*!") { diff --git a/src/formatting/vertical.rs b/src/formatting/vertical.rs index 4cfc05054fd..540e5858fa3 100644 --- a/src/formatting/vertical.rs +++ b/src/formatting/vertical.rs @@ -50,16 +50,15 @@ impl AlignedItem for ast::StructField { mk_sp(self.attrs.last().unwrap().span.hi(), self.span.lo()) }; let attrs_extendable = self.ident.is_none() && is_attributes_extendable(&attrs_str); - Some(rewrite_struct_field_prefix(context, self)).and_then(|field_str| { - combine_strs_with_missing_comments( - context, - &attrs_str, - &field_str, - missing_span, - shape, - attrs_extendable, - ) - }) + let prefix = rewrite_struct_field_prefix(context, self); + combine_strs_with_missing_comments( + context, + &attrs_str, + &prefix, + missing_span, + shape, + attrs_extendable, + ) } fn rewrite_aligned_item(