]> git.lizzy.rs Git - rust.git/blobdiff - src/lists.rs
Remove unnecessary references
[rust.git] / src / lists.rs
index 301e9101c8f5288c4f33ff4129e01adec1aa9392..42edc3d3d3c66cc62106739927827771e635647b 100644 (file)
@@ -114,7 +114,7 @@ pub struct ListItem {
 
 impl ListItem {
     pub fn inner_as_ref(&self) -> &str {
-        self.item.as_ref().map_or("", |s| &*s)
+        self.item.as_ref().map_or("", |s| s)
     }
 
     pub fn is_different_group(&self) -> bool {
@@ -265,7 +265,7 @@ pub fn write_list<I, T>(items: I, formatting: &ListFormatting) -> Option<String>
     // Now that we know how we will layout, we can decide for sure if there
     // will be a trailing separator.
     let mut trailing_separator = formatting.needs_trailing_separator();
-    let mut result = String::new();
+    let mut result = String::with_capacity(128);
     let cloned_items = items.clone();
     let mut iter = items.into_iter().enumerate().peekable();
     let mut item_max_width: Option<usize> = None;
@@ -641,7 +641,7 @@ fn next(&mut self) -> Option<Self::Item> {
             self.prev_span_end = (self.get_hi)(&item) + BytePos(comment_end as u32);
             let post_snippet = post_snippet[..comment_end].trim();
 
-            let post_snippet_trimmed = if post_snippet.starts_with(',') {
+            let post_snippet_trimmed = if post_snippet.starts_with(|c| c == ',' || c == ':') {
                 post_snippet[1..].trim_matches(white_space)
             } else if post_snippet.ends_with(',') {
                 post_snippet[..(post_snippet.len() - 1)].trim_matches(white_space)