]> git.lizzy.rs Git - rust.git/commitdiff
update print_visibility for new pub(restricted) syntax
authorAlex Burka <alex@alexburka.com>
Sun, 2 Apr 2017 04:46:33 +0000 (04:46 +0000)
committerAlex Burka <alex@alexburka.com>
Sat, 15 Apr 2017 19:06:19 +0000 (19:06 +0000)
src/libsyntax/print/pprust.rs

index 2494af2c1618692154384cd91152bc083869c66b..be1d26f8fe4872c5f82346707883d50141ee3c2c 100644 (file)
@@ -432,13 +432,7 @@ pub fn mac_to_string(arg: &ast::Mac) -> String {
 }
 
 pub fn visibility_qualified(vis: &ast::Visibility, s: &str) -> String {
-    match *vis {
-        ast::Visibility::Public => format!("pub {}", s),
-        ast::Visibility::Crate(_) => format!("pub(crate) {}", s),
-        ast::Visibility::Restricted { ref path, .. } =>
-            format!("pub({}) {}", to_string(|s| s.print_path(path, false, 0, true)), s),
-        ast::Visibility::Inherited => s.to_string()
-    }
+    format!("{}{}", to_string(|s| s.print_visibility(vis)), s)
 }
 
 fn needs_parentheses(expr: &ast::Expr) -> bool {
@@ -1473,7 +1467,11 @@ pub fn print_visibility(&mut self, vis: &ast::Visibility) -> io::Result<()> {
             ast::Visibility::Crate(_) => self.word_nbsp("pub(crate)"),
             ast::Visibility::Restricted { ref path, .. } => {
                 let path = to_string(|s| s.print_path(path, false, 0, true));
-                self.word_nbsp(&format!("pub({})", path))
+                if path == "self" || path == "super" {
+                    self.word_nbsp(&format!("pub({})", path))
+                } else {
+                    self.word_nbsp(&format!("pub(in {})", path))
+                }
             }
             ast::Visibility::Inherited => Ok(())
         }