Skip to content

Compute type fragments left over from moves #17439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add node_to_user_string, node_to_string variant that drops id fro…
…m output.
  • Loading branch information
pnkfelix committed Sep 22, 2014
commit 77d889f623f5ed39f02a5359fab77b564438a8a2
59 changes: 33 additions & 26 deletions src/libsyntax/ast_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,11 @@ impl<'ast> Map<'ast> {
}

pub fn node_to_string(&self, id: NodeId) -> String {
node_id_to_string(self, id)
node_id_to_string(self, id, true)
}

pub fn node_to_user_string(&self, id: NodeId) -> String {
node_id_to_string(self, id, false)
}
}

Expand Down Expand Up @@ -1012,7 +1016,10 @@ impl<'a> NodePrinter for pprust::State<'a> {
}
}

fn node_id_to_string(map: &Map, id: NodeId) -> String {
fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
let id_str = format!(" (id={})", id);
let id_str = if include_id { id_str.as_slice() } else { "" };

match map.find(id) {
Some(NodeItem(item)) => {
let path_str = map.path_to_str_with_ident(id, item.ident);
Expand All @@ -1028,82 +1035,82 @@ fn node_id_to_string(map: &Map, id: NodeId) -> String {
ItemImpl(..) => "impl",
ItemMac(..) => "macro"
};
format!("{} {} (id={})", item_str, path_str, id)
format!("{} {}{:s}", item_str, path_str, id_str)
}
Some(NodeForeignItem(item)) => {
let path_str = map.path_to_str_with_ident(id, item.ident);
format!("foreign item {} (id={})", path_str, id)
format!("foreign item {}{:s}", path_str, id_str)
}
Some(NodeImplItem(ref ii)) => {
match **ii {
MethodImplItem(ref m) => {
match m.node {
MethDecl(ident, _, _, _, _, _, _, _) =>
format!("method {} in {} (id={})",
format!("method {} in {}{:s}",
token::get_ident(ident),
map.path_to_string(id), id),
map.path_to_string(id), id_str),
MethMac(ref mac) =>
format!("method macro {} (id={})",
pprust::mac_to_string(mac), id)
format!("method macro {}{:s}",
pprust::mac_to_string(mac), id_str)
}
}
TypeImplItem(ref t) => {
format!("typedef {} in {} (id={})",
format!("typedef {} in {}{:s}",
token::get_ident(t.ident),
map.path_to_string(id),
id)
id_str)
}
}
}
Some(NodeTraitItem(ref tm)) => {
match **tm {
RequiredMethod(_) | ProvidedMethod(_) => {
let m = ast_util::trait_item_to_ty_method(&**tm);
format!("method {} in {} (id={})",
format!("method {} in {}{:s}",
token::get_ident(m.ident),
map.path_to_string(id),
id)
id_str)
}
TypeTraitItem(ref t) => {
format!("type item {} in {} (id={})",
format!("type item {} in {}{:s}",
token::get_ident(t.ident),
map.path_to_string(id),
id)
id_str)
}
}
}
Some(NodeVariant(ref variant)) => {
format!("variant {} in {} (id={})",
format!("variant {} in {}{:s}",
token::get_ident(variant.node.name),
map.path_to_string(id), id)
map.path_to_string(id), id_str)
}
Some(NodeExpr(ref expr)) => {
format!("expr {} (id={})", pprust::expr_to_string(&**expr), id)
format!("expr {}{:s}", pprust::expr_to_string(&**expr), id_str)
}
Some(NodeStmt(ref stmt)) => {
format!("stmt {} (id={})", pprust::stmt_to_string(&**stmt), id)
format!("stmt {}{:s}", pprust::stmt_to_string(&**stmt), id_str)
}
Some(NodeArg(ref pat)) => {
format!("arg {} (id={})", pprust::pat_to_string(&**pat), id)
format!("arg {}{:s}", pprust::pat_to_string(&**pat), id_str)
}
Some(NodeLocal(ref pat)) => {
format!("local {} (id={})", pprust::pat_to_string(&**pat), id)
format!("local {}{:s}", pprust::pat_to_string(&**pat), id_str)
}
Some(NodePat(ref pat)) => {
format!("pat {} (id={})", pprust::pat_to_string(&**pat), id)
format!("pat {}{:s}", pprust::pat_to_string(&**pat), id_str)
}
Some(NodeBlock(ref block)) => {
format!("block {} (id={})", pprust::block_to_string(&**block), id)
format!("block {}{:s}", pprust::block_to_string(&**block), id_str)
}
Some(NodeStructCtor(_)) => {
format!("struct_ctor {} (id={})", map.path_to_string(id), id)
format!("struct_ctor {}{:s}", map.path_to_string(id), id_str)
}
Some(NodeLifetime(ref l)) => {
format!("lifetime {} (id={})",
pprust::lifetime_to_string(&**l), id)
format!("lifetime {}{:s}",
pprust::lifetime_to_string(&**l), id_str)
}
None => {
format!("unknown node (id={})", id)
format!("unknown node{:s}", id_str)
}
}
}