@@ -124,22 +124,33 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
124
124
let mut result: Vec < ( Span , String ) > = vec ! ( ) ;
125
125
126
126
let mut segs = vec ! ( ) ;
127
- for ( seg, span) in path. segments . iter ( ) . zip ( spans. iter ( ) ) {
127
+ for ( i , ( seg, span) ) in path. segments . iter ( ) . zip ( spans. iter ( ) ) . enumerate ( ) {
128
128
segs. push ( seg. clone ( ) ) ;
129
129
let sub_path = ast:: Path { span : * span, // span for the last segment
130
130
global : path. global ,
131
131
segments : segs} ;
132
- let qualname = path_to_string ( & sub_path) ;
132
+ let qualname = if i == 0 && path. global {
133
+ let mut result = "::" . to_string ( ) ;
134
+ result. push_str ( & path_to_string ( & sub_path) [ ] ) ;
135
+ result
136
+ } else {
137
+ path_to_string ( & sub_path)
138
+ } ;
133
139
result. push ( ( * span, qualname) ) ;
134
140
segs = sub_path. segments ;
135
141
}
136
142
137
143
result
138
144
}
139
145
140
- fn write_sub_paths ( & mut self , path : & ast:: Path ) {
146
+ fn write_sub_paths ( & mut self , path : & ast:: Path , global : bool ) {
141
147
let sub_paths = self . process_path_prefixes ( path) ;
142
- for & ( ref span, ref qualname) in sub_paths. iter ( ) {
148
+ for ( i, & ( ref span, ref qualname) ) in sub_paths. iter ( ) . enumerate ( ) {
149
+ let qualname = if i == 0 && global && !path. global {
150
+ format ! ( "::{}" , qualname)
151
+ } else {
152
+ qualname. clone ( )
153
+ } ;
143
154
self . fmt . sub_mod_ref_str ( path. span ,
144
155
* span,
145
156
& qualname[ ] ,
@@ -149,15 +160,20 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
149
160
150
161
// As write_sub_paths, but does not process the last ident in the path (assuming it
151
162
// will be processed elsewhere).
152
- fn write_sub_paths_truncated ( & mut self , path : & ast:: Path ) {
163
+ fn write_sub_paths_truncated ( & mut self , path : & ast:: Path , global : bool ) {
153
164
let sub_paths = self . process_path_prefixes ( path) ;
154
165
let len = sub_paths. len ( ) ;
155
166
if len <= 1 {
156
167
return ;
157
168
}
158
169
159
- let sub_paths = & sub_paths[ .. ( len-1 ) ] ;
160
- for & ( ref span, ref qualname) in sub_paths. iter ( ) {
170
+ let sub_paths = sub_paths[ ..len-1 ] ;
171
+ for ( i, & ( ref span, ref qualname) ) in sub_paths. iter ( ) . enumerate ( ) {
172
+ let qualname = if i == 0 && global && !path. global {
173
+ format ! ( "::{}" , qualname)
174
+ } else {
175
+ qualname. clone ( )
176
+ } ;
161
177
self . fmt . sub_mod_ref_str ( path. span ,
162
178
* span,
163
179
& qualname[ ] ,
@@ -276,8 +292,8 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
276
292
let mut scope_id;
277
293
// The qualname for a method is the trait name or name of the struct in an impl in
278
294
// which the method is declared in followed by the method's name.
279
- let mut qualname = match ty:: impl_of_method ( & self . analysis . ty_cx ,
280
- ast_util:: local_def ( method. id ) ) {
295
+ let qualname = match ty:: impl_of_method ( & self . analysis . ty_cx ,
296
+ ast_util:: local_def ( method. id ) ) {
281
297
Some ( impl_id) => match self . analysis . ty_cx . map . get ( impl_id. node ) {
282
298
NodeItem ( item) => {
283
299
scope_id = item. id ;
@@ -339,7 +355,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
339
355
} ,
340
356
} ;
341
357
342
- qualname. push_str ( get_ident ( method. pe_ident ( ) ) . get ( ) ) ;
358
+ let qualname = format ! ( "::{}{}" , qualname , get_ident( method. pe_ident( ) ) . get( ) ) ;
343
359
let qualname = & qualname[ ] ;
344
360
345
361
// record the decl for this def (if it has one)
@@ -434,7 +450,8 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
434
450
}
435
451
436
452
// Dump generic params bindings, then visit_generics
437
- fn process_generic_params ( & mut self , generics : & ast:: Generics ,
453
+ fn process_generic_params ( & mut self ,
454
+ generics : & ast:: Generics ,
438
455
full_span : Span ,
439
456
prefix : & str ,
440
457
id : NodeId ) {
@@ -464,7 +481,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
464
481
decl : & ast:: FnDecl ,
465
482
ty_params : & ast:: Generics ,
466
483
body : & ast:: Block ) {
467
- let qualname = self . analysis . ty_cx . map . path_to_string ( item. id ) ;
484
+ let qualname = format ! ( "::{}" , self . analysis. ty_cx. map. path_to_string( item. id) ) ;
468
485
469
486
let sub_span = self . span . sub_span_after_keyword ( item. span , keywords:: Fn ) ;
470
487
self . fmt . fn_str ( item. span ,
@@ -496,7 +513,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
496
513
mt : ast:: Mutability ,
497
514
expr : & ast:: Expr )
498
515
{
499
- let qualname = self . analysis . ty_cx . map . path_to_string ( item. id ) ;
516
+ let qualname = format ! ( "::{}" , self . analysis. ty_cx. map. path_to_string( item. id) ) ;
500
517
501
518
// If the variable is immutable, save the initialising expression.
502
519
let value = match mt {
@@ -524,7 +541,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
524
541
typ : & ast:: Ty ,
525
542
expr : & ast:: Expr )
526
543
{
527
- let qualname = self . analysis . ty_cx . map . path_to_string ( item. id ) ;
544
+ let qualname = format ! ( "::{}" , self . analysis. ty_cx. map. path_to_string( item. id) ) ;
528
545
529
546
let sub_span = self . span . sub_span_after_keyword ( item. span ,
530
547
keywords:: Const ) ;
@@ -546,7 +563,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
546
563
item : & ast:: Item ,
547
564
def : & ast:: StructDef ,
548
565
ty_params : & ast:: Generics ) {
549
- let qualname = self . analysis . ty_cx . map . path_to_string ( item. id ) ;
566
+ let qualname = format ! ( "::{}" , self . analysis. ty_cx. map. path_to_string( item. id) ) ;
550
567
551
568
let ctor_id = match def. ctor_id {
552
569
Some ( node_id) => node_id,
@@ -575,7 +592,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
575
592
item : & ast:: Item ,
576
593
enum_definition : & ast:: EnumDef ,
577
594
ty_params : & ast:: Generics ) {
578
- let enum_name = self . analysis . ty_cx . map . path_to_string ( item. id ) ;
595
+ let enum_name = format ! ( "::{}" , self . analysis. ty_cx. map. path_to_string( item. id) ) ;
579
596
let val = self . span . snippet ( item. span ) ;
580
597
match self . span . sub_span_after_keyword ( item. span , keywords:: Enum ) {
581
598
Some ( sub_span) => self . fmt . enum_str ( item. span ,
@@ -701,7 +718,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
701
718
generics : & ast:: Generics ,
702
719
trait_refs : & OwnedSlice < ast:: TyParamBound > ,
703
720
methods : & Vec < ast:: TraitItem > ) {
704
- let qualname = self . analysis . ty_cx . map . path_to_string ( item. id ) ;
721
+ let qualname = format ! ( "::{}" , self . analysis. ty_cx. map. path_to_string( item. id) ) ;
705
722
let val = self . span . snippet ( item. span ) ;
706
723
let sub_span = self . span . sub_span_after_keyword ( item. span , keywords:: Trait ) ;
707
724
self . fmt . trait_str ( item. span ,
@@ -750,7 +767,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
750
767
fn process_mod ( & mut self ,
751
768
item : & ast:: Item , // The module in question, represented as an item.
752
769
m : & ast:: Mod ) {
753
- let qualname = self . analysis . ty_cx . map . path_to_string ( item. id ) ;
770
+ let qualname = format ! ( "::{}" , self . analysis. ty_cx. map. path_to_string( item. id) ) ;
754
771
755
772
let cm = self . sess . codemap ( ) ;
756
773
let filename = cm. span_to_filename ( m. inner ) ;
@@ -855,7 +872,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
855
872
def:: DefConst ( ..) |
856
873
def:: DefStruct ( _) |
857
874
def:: DefVariant ( ..) |
858
- def:: DefFn ( ..) => self . write_sub_paths_truncated ( path) ,
875
+ def:: DefFn ( ..) => self . write_sub_paths_truncated ( path, false ) ,
859
876
_ => { } ,
860
877
}
861
878
}
@@ -883,7 +900,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
883
900
None => ( )
884
901
}
885
902
886
- self . write_sub_paths_truncated ( path) ;
903
+ self . write_sub_paths_truncated ( path, false ) ;
887
904
888
905
for field in fields. iter ( ) {
889
906
match struct_def {
@@ -1069,7 +1086,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1069
1086
mod_id,
1070
1087
get_ident ( ident) . get ( ) ,
1071
1088
self . cur_scope ) ;
1072
- self . write_sub_paths_truncated ( path) ;
1089
+ self . write_sub_paths_truncated ( path, true ) ;
1073
1090
}
1074
1091
ast:: ViewPathGlob ( ref path) => {
1075
1092
// Make a comma-separated list of names of imported modules.
@@ -1092,7 +1109,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1092
1109
item. id ,
1093
1110
name_string. as_slice ( ) ,
1094
1111
self . cur_scope ) ;
1095
- self . write_sub_paths ( path) ;
1112
+ self . write_sub_paths ( path, true ) ;
1096
1113
}
1097
1114
ast:: ViewPathList ( ref path, ref list) => {
1098
1115
for plid in list. iter ( ) {
@@ -1116,7 +1133,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1116
1133
}
1117
1134
}
1118
1135
1119
- self . write_sub_paths ( path) ;
1136
+ self . write_sub_paths ( path, true ) ;
1120
1137
}
1121
1138
}
1122
1139
}
@@ -1163,7 +1180,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1163
1180
self . process_trait ( item, generics, trait_refs, methods) ,
1164
1181
ast:: ItemMod ( ref m) => self . process_mod ( item, m) ,
1165
1182
ast:: ItemTy ( ref ty, ref ty_params) => {
1166
- let qualname = self . analysis . ty_cx . map . path_to_string ( item. id ) ;
1183
+ let qualname = format ! ( "::{}" , self . analysis. ty_cx. map. path_to_string( item. id) ) ;
1167
1184
let value = ty_to_string ( & * * ty) ;
1168
1185
let sub_span = self . span . sub_span_after_keyword ( item. span , keywords:: Type ) ;
1169
1186
self . fmt . typedef_str ( item. span ,
@@ -1223,9 +1240,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1223
1240
ast_util:: local_def ( method_type. id ) ) {
1224
1241
Some ( def_id) => {
1225
1242
scope_id = def_id. node ;
1226
- let mut s = ty:: item_path_str ( & self . analysis . ty_cx , def_id) ;
1227
- s. push_str ( "::" ) ;
1228
- s
1243
+ format ! ( "::{}::" , ty:: item_path_str( & self . analysis. ty_cx, def_id) )
1229
1244
} ,
1230
1245
None => {
1231
1246
self . sess . span_bug ( method_type. span ,
@@ -1282,7 +1297,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
1282
1297
None => ( )
1283
1298
}
1284
1299
1285
- self . write_sub_paths_truncated ( path) ;
1300
+ self . write_sub_paths_truncated ( path, false ) ;
1286
1301
1287
1302
visit:: walk_path ( self , path) ;
1288
1303
} ,
0 commit comments