}
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 {
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(())
}