]> git.lizzy.rs Git - rust.git/commitdiff
Move the empty path_list handling into rewrite_use_list()
authorCaleb Jones <code@calebjones.net>
Mon, 7 Aug 2017 03:04:33 +0000 (23:04 -0400)
committerCaleb Jones <code@calebjones.net>
Mon, 7 Aug 2017 03:04:33 +0000 (23:04 -0400)
src/imports.rs

index 6b1a2f541eac432faaa9787fbd07b0a5692aead7..a65d8bb066a85b8596179db9f2b37535ccc93464 100644 (file)
@@ -157,12 +157,8 @@ fn rewrite_view_path_prefix(
 }
 
 impl Rewrite for ast::ViewPath {
-    // Returns an empty string when the ViewPath is empty (like foo::bar::{})
     fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
         match self.node {
-            ast::ViewPath_::ViewPathList(_, ref path_list) if path_list.is_empty() => {
-                Some(String::new())
-            }
             ast::ViewPath_::ViewPathList(ref path, ref path_list) => {
                 rewrite_use_list(shape, path, path_list, self.span, context)
             }
@@ -263,12 +259,11 @@ pub fn format_import(
             .offset_left(vis.len() + 4)
             .and_then(|shape| shape.sub_width(1))
             .and_then(|shape| match vp.node {
-                // If we have an empty path with attributes attached, we want to skip erasing it
-                ast::ViewPath_::ViewPathList(ref path, ref path_list)
-                    if path_list.is_empty() && !attrs.is_empty() =>
+                // If we have an empty path list with no attributes, we erase it
+                ast::ViewPath_::ViewPathList(_, ref path_list)
+                    if path_list.is_empty() && attrs.is_empty() =>
                 {
-                    rewrite_path(&self.get_context(), PathContext::Import, None, path, shape)
-                        .map(|path_str| format!("{}::{{}}", path_str))
+                    Some("".into())
                 }
                 _ => vp.rewrite(&self.get_context(), shape),
             });
@@ -400,7 +395,7 @@ fn cmp(&self, other: &ImportItem<'a>) -> Ordering {
 }
 
 // Pretty prints a multi-item import.
-// Assumes that path_list.len() > 0.
+// If the path list is empty, it leaves the braces empty.
 fn rewrite_use_list(
     shape: Shape,
     path: &ast::Path,
@@ -418,7 +413,10 @@ fn rewrite_use_list(
     ));
 
     match path_list.len() {
-        0 => unreachable!(),
+        0 => {
+            return rewrite_path(context, PathContext::Import, None, path, shape)
+                .map(|path_str| format!("{}::{{}}", path_str));
+        }
         1 => return Some(rewrite_single_use_list(path_str, &path_list[0])),
         _ => (),
     }