AST: Keep distinction between path and ::path in imports and visibilities
Add the root segment for name resolution purposes only
This commit is contained in:
@@ -353,7 +353,7 @@ pub fn fn_block_to_string(p: &ast::FnDecl) -> String {
|
||||
}
|
||||
|
||||
pub fn path_to_string(p: &ast::Path) -> String {
|
||||
to_string(|s| s.print_path(p, false, 0, false))
|
||||
to_string(|s| s.print_path(p, false, 0))
|
||||
}
|
||||
|
||||
pub fn path_segment_to_string(p: &ast::PathSegment) -> String {
|
||||
@@ -1051,7 +1051,7 @@ impl<'a> State<'a> {
|
||||
&f.generic_params)?;
|
||||
}
|
||||
ast::TyKind::Path(None, ref path) => {
|
||||
self.print_path(path, false, 0, false)?;
|
||||
self.print_path(path, false, 0)?;
|
||||
}
|
||||
ast::TyKind::Path(Some(ref qself), ref path) => {
|
||||
self.print_qpath(path, qself, false)?
|
||||
@@ -1378,7 +1378,7 @@ impl<'a> State<'a> {
|
||||
self.s.word(";")?;
|
||||
}
|
||||
ast::ItemKind::Mac(codemap::Spanned { ref node, .. }) => {
|
||||
self.print_path(&node.path, false, 0, false)?;
|
||||
self.print_path(&node.path, false, 0)?;
|
||||
self.s.word("! ")?;
|
||||
self.print_ident(item.ident)?;
|
||||
self.cbox(INDENT_UNIT)?;
|
||||
@@ -1403,7 +1403,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
|
||||
fn print_trait_ref(&mut self, t: &ast::TraitRef) -> io::Result<()> {
|
||||
self.print_path(&t.path, false, 0, false)
|
||||
self.print_path(&t.path, false, 0)
|
||||
}
|
||||
|
||||
fn print_formal_generic_params(
|
||||
@@ -1460,7 +1460,7 @@ impl<'a> State<'a> {
|
||||
ast::CrateSugar::JustCrate => self.word_nbsp("crate")
|
||||
}
|
||||
ast::VisibilityKind::Restricted { ref path, .. } => {
|
||||
let path = to_string(|s| s.print_path(path, false, 0, true));
|
||||
let path = to_string(|s| s.print_path(path, false, 0));
|
||||
if path == "self" || path == "super" {
|
||||
self.word_nbsp(&format!("pub({})", path))
|
||||
} else {
|
||||
@@ -1594,7 +1594,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
ast::TraitItemKind::Macro(codemap::Spanned { ref node, .. }) => {
|
||||
// code copied from ItemKind::Mac:
|
||||
self.print_path(&node.path, false, 0, false)?;
|
||||
self.print_path(&node.path, false, 0)?;
|
||||
self.s.word("! ")?;
|
||||
self.cbox(INDENT_UNIT)?;
|
||||
self.popen()?;
|
||||
@@ -1628,7 +1628,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
ast::ImplItemKind::Macro(codemap::Spanned { ref node, .. }) => {
|
||||
// code copied from ItemKind::Mac:
|
||||
self.print_path(&node.path, false, 0, false)?;
|
||||
self.print_path(&node.path, false, 0)?;
|
||||
self.s.word("! ")?;
|
||||
self.cbox(INDENT_UNIT)?;
|
||||
self.popen()?;
|
||||
@@ -1814,7 +1814,7 @@ impl<'a> State<'a> {
|
||||
|
||||
pub fn print_mac(&mut self, m: &ast::Mac, delim: token::DelimToken)
|
||||
-> io::Result<()> {
|
||||
self.print_path(&m.node.path, false, 0, false)?;
|
||||
self.print_path(&m.node.path, false, 0)?;
|
||||
self.s.word("!")?;
|
||||
match delim {
|
||||
token::Paren => self.popen()?,
|
||||
@@ -1915,7 +1915,7 @@ impl<'a> State<'a> {
|
||||
fields: &[ast::Field],
|
||||
wth: &Option<P<ast::Expr>>,
|
||||
attrs: &[Attribute]) -> io::Result<()> {
|
||||
self.print_path(path, true, 0, false)?;
|
||||
self.print_path(path, true, 0)?;
|
||||
self.s.word("{")?;
|
||||
self.print_inner_attributes_inline(attrs)?;
|
||||
self.commasep_cmnt(
|
||||
@@ -2236,7 +2236,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
ast::ExprKind::Path(None, ref path) => {
|
||||
self.print_path(path, true, 0, false)?
|
||||
self.print_path(path, true, 0)?
|
||||
}
|
||||
ast::ExprKind::Path(Some(ref qself), ref path) => {
|
||||
self.print_qpath(path, qself, true)?
|
||||
@@ -2396,17 +2396,12 @@ impl<'a> State<'a> {
|
||||
fn print_path(&mut self,
|
||||
path: &ast::Path,
|
||||
colons_before_params: bool,
|
||||
depth: usize,
|
||||
defaults_to_global: bool)
|
||||
depth: usize)
|
||||
-> io::Result<()>
|
||||
{
|
||||
self.maybe_print_comment(path.span.lo())?;
|
||||
|
||||
let mut segments = path.segments[..path.segments.len()-depth].iter();
|
||||
if defaults_to_global && path.is_global() {
|
||||
segments.next();
|
||||
}
|
||||
for (i, segment) in segments.enumerate() {
|
||||
for (i, segment) in path.segments[..path.segments.len() - depth].iter().enumerate() {
|
||||
if i > 0 {
|
||||
self.s.word("::")?
|
||||
}
|
||||
@@ -2445,7 +2440,7 @@ impl<'a> State<'a> {
|
||||
self.s.space()?;
|
||||
self.word_space("as")?;
|
||||
let depth = path.segments.len() - qself.position;
|
||||
self.print_path(path, false, depth, false)?;
|
||||
self.print_path(path, false, depth)?;
|
||||
}
|
||||
self.s.word(">")?;
|
||||
self.s.word("::")?;
|
||||
@@ -2548,7 +2543,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
PatKind::TupleStruct(ref path, ref elts, ddpos) => {
|
||||
self.print_path(path, true, 0, false)?;
|
||||
self.print_path(path, true, 0)?;
|
||||
self.popen()?;
|
||||
if let Some(ddpos) = ddpos {
|
||||
self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(p))?;
|
||||
@@ -2566,13 +2561,13 @@ impl<'a> State<'a> {
|
||||
self.pclose()?;
|
||||
}
|
||||
PatKind::Path(None, ref path) => {
|
||||
self.print_path(path, true, 0, false)?;
|
||||
self.print_path(path, true, 0)?;
|
||||
}
|
||||
PatKind::Path(Some(ref qself), ref path) => {
|
||||
self.print_qpath(path, qself, false)?;
|
||||
}
|
||||
PatKind::Struct(ref path, ref fields, etc) => {
|
||||
self.print_path(path, true, 0, false)?;
|
||||
self.print_path(path, true, 0)?;
|
||||
self.nbsp()?;
|
||||
self.word_space("{")?;
|
||||
self.commasep_cmnt(
|
||||
@@ -2950,7 +2945,7 @@ impl<'a> State<'a> {
|
||||
pub fn print_use_tree(&mut self, tree: &ast::UseTree) -> io::Result<()> {
|
||||
match tree.kind {
|
||||
ast::UseTreeKind::Simple(rename) => {
|
||||
self.print_path(&tree.prefix, false, 0, true)?;
|
||||
self.print_path(&tree.prefix, false, 0)?;
|
||||
if let Some(rename) = rename {
|
||||
self.s.space()?;
|
||||
self.word_space("as")?;
|
||||
@@ -2959,7 +2954,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
ast::UseTreeKind::Glob => {
|
||||
if !tree.prefix.segments.is_empty() {
|
||||
self.print_path(&tree.prefix, false, 0, true)?;
|
||||
self.print_path(&tree.prefix, false, 0)?;
|
||||
self.s.word("::")?;
|
||||
}
|
||||
self.s.word("*")?;
|
||||
@@ -2968,7 +2963,7 @@ impl<'a> State<'a> {
|
||||
if tree.prefix.segments.is_empty() {
|
||||
self.s.word("{")?;
|
||||
} else {
|
||||
self.print_path(&tree.prefix, false, 0, true)?;
|
||||
self.print_path(&tree.prefix, false, 0)?;
|
||||
self.s.word("::{")?;
|
||||
}
|
||||
self.commasep(Inconsistent, &items[..], |this, &(ref tree, _)| {
|
||||
|
||||
Reference in New Issue
Block a user