]> git.lizzy.rs Git - rust.git/commitdiff
Handle pub use (fixes #23)
authorManish Goregaokar <manishsmail@gmail.com>
Thu, 30 Apr 2015 08:03:26 +0000 (13:33 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Thu, 30 Apr 2015 08:22:28 +0000 (13:52 +0530)
src/imports.rs
src/visitor.rs
tests/idem/imports.rs

index 1532050522a2053591b7f410c6ca04518f6e4a63..59bac9d73a7ea6468b1600686cb809b084c6f547 100644 (file)
@@ -27,12 +27,17 @@ impl<'a> FmtVisitor<'a> {
     pub fn rewrite_use_list(&mut self,
                             path: &ast::Path,
                             path_list: &[ast::PathListItem],
+                            visibility: ast::Visibility,
                             vp_span: Span) -> String {
         // FIXME check indentation
         let l_loc = self.codemap.lookup_char_pos(vp_span.lo);
 
         let path_str = pprust::path_to_string(&path);
 
+        let vis = match visibility {
+            ast::Public => "pub ",
+            _ => ""
+        };
 
         // 1 = {
         let mut indent = l_loc.col.0 + path_str.len() + 1;
@@ -41,7 +46,7 @@ pub fn rewrite_use_list(&mut self,
             indent += 2;
         }
         // 2 = } + ;
-        let used_width = indent + 2;
+        let used_width = indent + 2 + vis.len();
         let budget = if used_width >= IDEAL_WIDTH {
             if used_width < MAX_WIDTH {
                 MAX_WIDTH - used_width
@@ -84,11 +89,10 @@ pub fn rewrite_use_list(&mut self,
                 ast::PathListItem_::PathListMod{ .. } => None,
             }
         })).collect();
-
         if path_str.len() == 0 {
-            format!("use {{{}}};", write_list(&items, &fmt))
+            format!("{}use {{{}}};", vis, write_list(&items, &fmt))
         } else {
-            format!("use {}::{{{}}};", path_str, write_list(&items, &fmt))
+            format!("{}use {}::{{{}}};", vis, path_str, write_list(&items, &fmt))
         }
     }
 }
index 75dcdb12601d3abbf732417b0130f569f43bb06b..5b99d700c9c75c94548ec3f6678dfd43bbb20982 100644 (file)
@@ -148,7 +148,10 @@ fn visit_item(&mut self, item: &'v ast::Item) {
                 match vp.node {
                     ast::ViewPath_::ViewPathList(ref path, ref path_list) => {
                         self.format_missing(item.span.lo);
-                        let new_str = self.rewrite_use_list(path, path_list, vp.span);
+                        let new_str = self.rewrite_use_list(path,
+                                                            path_list,
+                                                            item.vis,
+                                                            vp.span);
                         self.changes.push_str_span(item.span, &new_str);
                         self.last_pos = item.span.hi;
                     }
index 9891994c66e76c4f609fae5bfe7024abaff1f911..13910c8a6281984f6d7dabaa0abf6f36e57f9d01 100644 (file)
@@ -6,3 +6,5 @@
 
 use {Foo, Bar};
 use Foo::{Bar, Baz};
+pub use syntax::ast::{Expr_, Expr, ExprAssign, ExprCall, ExprMethodCall,
+                      ExprPath};