@@ -551,7 +551,11 @@ impl<'ast> Map<'ast> {
551
551
}
552
552
553
553
pub fn node_to_string ( & self , id : NodeId ) -> String {
554
- node_id_to_string ( self , id)
554
+ node_id_to_string ( self , id, true )
555
+ }
556
+
557
+ pub fn node_to_user_string ( & self , id : NodeId ) -> String {
558
+ node_id_to_string ( self , id, false )
555
559
}
556
560
}
557
561
@@ -1028,7 +1032,10 @@ impl<'a> NodePrinter for pprust::State<'a> {
1028
1032
}
1029
1033
}
1030
1034
1031
- fn node_id_to_string ( map : & Map , id : NodeId ) -> String {
1035
+ fn node_id_to_string ( map : & Map , id : NodeId , include_id : bool ) -> String {
1036
+ let id_str = format ! ( " (id={})" , id) ;
1037
+ let id_str = if include_id { id_str. as_slice ( ) } else { "" } ;
1038
+
1032
1039
match map. find ( id) {
1033
1040
Some ( NodeItem ( item) ) => {
1034
1041
let path_str = map. path_to_str_with_ident ( id, item. ident ) ;
@@ -1045,82 +1052,82 @@ fn node_id_to_string(map: &Map, id: NodeId) -> String {
1045
1052
ItemImpl ( ..) => "impl" ,
1046
1053
ItemMac ( ..) => "macro"
1047
1054
} ;
1048
- format ! ( "{} {} (id={}) " , item_str, path_str, id )
1055
+ format ! ( "{} {}{} " , item_str, path_str, id_str )
1049
1056
}
1050
1057
Some ( NodeForeignItem ( item) ) => {
1051
1058
let path_str = map. path_to_str_with_ident ( id, item. ident ) ;
1052
- format ! ( "foreign item {} (id={}) " , path_str, id )
1059
+ format ! ( "foreign item {}{} " , path_str, id_str )
1053
1060
}
1054
1061
Some ( NodeImplItem ( ref ii) ) => {
1055
1062
match * * ii {
1056
1063
MethodImplItem ( ref m) => {
1057
1064
match m. node {
1058
1065
MethDecl ( ident, _, _, _, _, _, _, _) =>
1059
- format ! ( "method {} in {} (id={}) " ,
1066
+ format ! ( "method {} in {}{} " ,
1060
1067
token:: get_ident( ident) ,
1061
- map. path_to_string( id) , id ) ,
1068
+ map. path_to_string( id) , id_str ) ,
1062
1069
MethMac ( ref mac) =>
1063
- format ! ( "method macro {} (id={}) " ,
1064
- pprust:: mac_to_string( mac) , id )
1070
+ format ! ( "method macro {}{} " ,
1071
+ pprust:: mac_to_string( mac) , id_str )
1065
1072
}
1066
1073
}
1067
1074
TypeImplItem ( ref t) => {
1068
- format ! ( "typedef {} in {} (id={}) " ,
1075
+ format ! ( "typedef {} in {}{} " ,
1069
1076
token:: get_ident( t. ident) ,
1070
1077
map. path_to_string( id) ,
1071
- id )
1078
+ id_str )
1072
1079
}
1073
1080
}
1074
1081
}
1075
1082
Some ( NodeTraitItem ( ref tm) ) => {
1076
1083
match * * tm {
1077
1084
RequiredMethod ( _) | ProvidedMethod ( _) => {
1078
1085
let m = ast_util:: trait_item_to_ty_method ( & * * tm) ;
1079
- format ! ( "method {} in {} (id={}) " ,
1086
+ format ! ( "method {} in {}{} " ,
1080
1087
token:: get_ident( m. ident) ,
1081
1088
map. path_to_string( id) ,
1082
- id )
1089
+ id_str )
1083
1090
}
1084
1091
TypeTraitItem ( ref t) => {
1085
- format ! ( "type item {} in {} (id={}) " ,
1092
+ format ! ( "type item {} in {}{} " ,
1086
1093
token:: get_ident( t. ty_param. ident) ,
1087
1094
map. path_to_string( id) ,
1088
- id )
1095
+ id_str )
1089
1096
}
1090
1097
}
1091
1098
}
1092
1099
Some ( NodeVariant ( ref variant) ) => {
1093
- format ! ( "variant {} in {} (id={}) " ,
1100
+ format ! ( "variant {} in {}{} " ,
1094
1101
token:: get_ident( variant. node. name) ,
1095
- map. path_to_string( id) , id )
1102
+ map. path_to_string( id) , id_str )
1096
1103
}
1097
1104
Some ( NodeExpr ( ref expr) ) => {
1098
- format ! ( "expr {} (id={}) " , pprust:: expr_to_string( & * * expr) , id )
1105
+ format ! ( "expr {}{} " , pprust:: expr_to_string( & * * expr) , id_str )
1099
1106
}
1100
1107
Some ( NodeStmt ( ref stmt) ) => {
1101
- format ! ( "stmt {} (id={}) " , pprust:: stmt_to_string( & * * stmt) , id )
1108
+ format ! ( "stmt {}{} " , pprust:: stmt_to_string( & * * stmt) , id_str )
1102
1109
}
1103
1110
Some ( NodeArg ( ref pat) ) => {
1104
- format ! ( "arg {} (id={}) " , pprust:: pat_to_string( & * * pat) , id )
1111
+ format ! ( "arg {}{} " , pprust:: pat_to_string( & * * pat) , id_str )
1105
1112
}
1106
1113
Some ( NodeLocal ( ref pat) ) => {
1107
- format ! ( "local {} (id={}) " , pprust:: pat_to_string( & * * pat) , id )
1114
+ format ! ( "local {}{} " , pprust:: pat_to_string( & * * pat) , id_str )
1108
1115
}
1109
1116
Some ( NodePat ( ref pat) ) => {
1110
- format ! ( "pat {} (id={}) " , pprust:: pat_to_string( & * * pat) , id )
1117
+ format ! ( "pat {}{} " , pprust:: pat_to_string( & * * pat) , id_str )
1111
1118
}
1112
1119
Some ( NodeBlock ( ref block) ) => {
1113
- format ! ( "block {} (id={}) " , pprust:: block_to_string( & * * block) , id )
1120
+ format ! ( "block {}{} " , pprust:: block_to_string( & * * block) , id_str )
1114
1121
}
1115
1122
Some ( NodeStructCtor ( _) ) => {
1116
- format ! ( "struct_ctor {} (id={}) " , map. path_to_string( id) , id )
1123
+ format ! ( "struct_ctor {}{} " , map. path_to_string( id) , id_str )
1117
1124
}
1118
1125
Some ( NodeLifetime ( ref l) ) => {
1119
- format ! ( "lifetime {} (id={}) " ,
1120
- pprust:: lifetime_to_string( & * * l) , id )
1126
+ format ! ( "lifetime {}{} " ,
1127
+ pprust:: lifetime_to_string( & * * l) , id_str )
1121
1128
}
1122
1129
None => {
1123
- format ! ( "unknown node (id={}) " , id )
1130
+ format ! ( "unknown node{} " , id_str )
1124
1131
}
1125
1132
}
1126
1133
}
0 commit comments