16
16
use rustc:: hir:: def:: Def as HirDef ;
17
17
use rustc:: hir:: def_id:: DefId ;
18
18
use rustc:: session:: config:: Input ;
19
+ use rustc:: span_bug;
19
20
use rustc:: ty:: { self , TyCtxt } ;
20
21
use rustc_data_structures:: fx:: FxHashSet ;
21
22
@@ -32,16 +33,20 @@ use syntax::print::pprust::{
32
33
} ;
33
34
use syntax:: ptr:: P ;
34
35
use syntax:: source_map:: { Spanned , DUMMY_SP , respan} ;
36
+ use syntax:: walk_list;
35
37
use syntax_pos:: * ;
36
38
37
- use { escape, generated_code, lower_attributes, PathCollector , SaveContext } ;
38
- use json_dumper:: { Access , DumpOutput , JsonDumper } ;
39
- use span_utils:: SpanUtils ;
40
- use sig;
39
+ use crate :: { escape, generated_code, id_from_def_id, id_from_node_id, lower_attributes,
40
+ PathCollector , SaveContext } ;
41
+ use crate :: json_dumper:: { Access , DumpOutput , JsonDumper } ;
42
+ use crate :: span_utils:: SpanUtils ;
43
+ use crate :: sig;
41
44
42
45
use rls_data:: { CompilationOptions , CratePreludeData , Def , DefKind , GlobalCrateId , Import ,
43
46
ImportKind , Ref , RefKind , Relation , RelationKind , SpanData } ;
44
47
48
+ use log:: { debug, error} ;
49
+
45
50
macro_rules! down_cast_data {
46
51
( $id: ident, $kind: ident, $sp: expr) => {
47
52
let $id = if let super :: Data :: $kind( data) = $id {
@@ -68,7 +73,7 @@ macro_rules! access_from {
68
73
} ;
69
74
}
70
75
71
- pub struct DumpVisitor < ' l , ' tcx : ' l , ' ll , O : DumpOutput + ' ll > {
76
+ pub struct DumpVisitor < ' l , ' tcx : ' l , ' ll , O : DumpOutput > {
72
77
save_ctxt : SaveContext < ' l , ' tcx > ,
73
78
tcx : TyCtxt < ' l , ' tcx , ' tcx > ,
74
79
dumper : & ' ll mut JsonDumper < O > ,
@@ -245,7 +250,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
245
250
None => continue ,
246
251
} ;
247
252
if !self . span . filter_generated ( ident. span ) {
248
- let id = :: id_from_node_id ( id, & self . save_ctxt ) ;
253
+ let id = id_from_node_id ( id, & self . save_ctxt ) ;
249
254
let span = self . span_from_span ( ident. span ) ;
250
255
251
256
self . dumper . dump_def (
@@ -286,7 +291,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
286
291
debug ! ( "process_method: {}:{}" , id, ident) ;
287
292
288
293
if let Some ( mut method_data) = self . save_ctxt . get_method_data ( id, ident, span) {
289
- let sig_str = :: make_signature ( & sig. decl , & generics) ;
294
+ let sig_str = crate :: make_signature ( & sig. decl , & generics) ;
290
295
if body. is_some ( ) {
291
296
self . nest_tables (
292
297
id,
@@ -339,7 +344,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
339
344
// Append $id to name to make sure each one is unique.
340
345
let qualname = format ! ( "{}::{}${}" , prefix, name, id) ;
341
346
if !self . span . filter_generated ( param_ss) {
342
- let id = :: id_from_node_id ( param. id , & self . save_ctxt ) ;
347
+ let id = id_from_node_id ( param. id , & self . save_ctxt ) ;
343
348
let span = self . span_from_span ( param_ss) ;
344
349
345
350
self . dumper . dump_def (
@@ -433,12 +438,12 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
433
438
& access_from ! ( self . save_ctxt, vis, id) ,
434
439
Def {
435
440
kind : DefKind :: Const ,
436
- id : :: id_from_node_id ( id, & self . save_ctxt ) ,
441
+ id : id_from_node_id ( id, & self . save_ctxt ) ,
437
442
span,
438
443
name : ident. name . to_string ( ) ,
439
444
qualname,
440
445
value : ty_to_string ( & typ) ,
441
- parent : Some ( :: id_from_def_id ( parent_id) ) ,
446
+ parent : Some ( id_from_def_id ( parent_id) ) ,
442
447
children : vec ! [ ] ,
443
448
decl_id : None ,
444
449
docs : self . save_ctxt . docs_for_attrs ( attrs) ,
@@ -495,7 +500,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
495
500
value,
496
501
fields
497
502
. iter ( )
498
- . map ( |f| :: id_from_node_id ( f. id , & self . save_ctxt ) )
503
+ . map ( |f| id_from_node_id ( f. id , & self . save_ctxt ) )
499
504
. collect ( ) ,
500
505
)
501
506
}
@@ -508,7 +513,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
508
513
& access_from ! ( self . save_ctxt, item) ,
509
514
Def {
510
515
kind,
511
- id : :: id_from_node_id ( item. id , & self . save_ctxt ) ,
516
+ id : id_from_node_id ( item. id , & self . save_ctxt ) ,
512
517
span,
513
518
name,
514
519
qualname : qualname. clone ( ) ,
@@ -564,8 +569,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
564
569
let value = format ! ( "{}::{} {{ {} }}" , enum_data. name, name, fields_str) ;
565
570
if !self . span . filter_generated ( name_span) {
566
571
let span = self . span_from_span ( name_span) ;
567
- let id = :: id_from_node_id ( variant. node . data . id ( ) , & self . save_ctxt ) ;
568
- let parent = Some ( :: id_from_node_id ( item. id , & self . save_ctxt ) ) ;
572
+ let id = id_from_node_id ( variant. node . data . id ( ) , & self . save_ctxt ) ;
573
+ let parent = Some ( id_from_node_id ( item. id , & self . save_ctxt ) ) ;
569
574
570
575
self . dumper . dump_def (
571
576
& access,
@@ -602,8 +607,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
602
607
}
603
608
if !self . span . filter_generated ( name_span) {
604
609
let span = self . span_from_span ( name_span) ;
605
- let id = :: id_from_node_id ( variant. node . data . id ( ) , & self . save_ctxt ) ;
606
- let parent = Some ( :: id_from_node_id ( item. id , & self . save_ctxt ) ) ;
610
+ let id = id_from_node_id ( variant. node . data . id ( ) , & self . save_ctxt ) ;
611
+ let parent = Some ( id_from_node_id ( item. id , & self . save_ctxt ) ) ;
607
612
608
613
self . dumper . dump_def (
609
614
& access,
@@ -686,11 +691,11 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
686
691
val. push_str ( & bounds_to_string ( trait_refs) ) ;
687
692
}
688
693
if !self . span . filter_generated ( item. ident . span ) {
689
- let id = :: id_from_node_id ( item. id , & self . save_ctxt ) ;
694
+ let id = id_from_node_id ( item. id , & self . save_ctxt ) ;
690
695
let span = self . span_from_span ( item. ident . span ) ;
691
696
let children = methods
692
697
. iter ( )
693
- . map ( |i| :: id_from_node_id ( i. id , & self . save_ctxt ) )
698
+ . map ( |i| id_from_node_id ( i. id , & self . save_ctxt ) )
694
699
. collect ( ) ;
695
700
self . dumper . dump_def (
696
701
& access_from ! ( self . save_ctxt, item) ,
@@ -726,14 +731,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
726
731
self . dumper . dump_ref ( Ref {
727
732
kind : RefKind :: Type ,
728
733
span : span. clone ( ) ,
729
- ref_id : :: id_from_def_id ( id) ,
734
+ ref_id : id_from_def_id ( id) ,
730
735
} ) ;
731
736
732
737
self . dumper . dump_relation ( Relation {
733
738
kind : RelationKind :: SuperTrait ,
734
739
span,
735
- from : :: id_from_def_id ( id) ,
736
- to : :: id_from_node_id ( item. id , & self . save_ctxt ) ,
740
+ from : id_from_def_id ( id) ,
741
+ to : id_from_node_id ( item. id , & self . save_ctxt ) ,
737
742
} ) ;
738
743
}
739
744
}
@@ -873,7 +878,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
873
878
self . dumper . dump_ref ( Ref {
874
879
kind : RefKind :: Variable ,
875
880
span,
876
- ref_id : :: id_from_def_id ( variant. fields [ index] . did ) ,
881
+ ref_id : id_from_def_id ( variant. fields [ index] . did ) ,
877
882
} ) ;
878
883
}
879
884
}
@@ -912,7 +917,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
912
917
913
918
if !self . span . filter_generated ( ident. span ) {
914
919
let qualname = format ! ( "{}${}" , ident. to_string( ) , id) ;
915
- let id = :: id_from_node_id ( id, & self . save_ctxt ) ;
920
+ let id = id_from_node_id ( id, & self . save_ctxt ) ;
916
921
let span = self . span_from_span ( ident. span ) ;
917
922
918
923
self . dumper . dump_def (
@@ -988,7 +993,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
988
993
// Rust uses the id of the pattern for var lookups, so we'll use it too.
989
994
if !self . span . filter_generated ( ident. span ) {
990
995
let qualname = format ! ( "{}${}" , ident. to_string( ) , id) ;
991
- let id = :: id_from_node_id ( id, & self . save_ctxt ) ;
996
+ let id = id_from_node_id ( id, & self . save_ctxt ) ;
992
997
let span = self . span_from_span ( ident. span ) ;
993
998
994
999
self . dumper . dump_def (
@@ -1091,7 +1096,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1091
1096
1092
1097
if !self . span . filter_generated ( trait_item. ident . span ) {
1093
1098
let span = self . span_from_span ( trait_item. ident . span ) ;
1094
- let id = :: id_from_node_id ( trait_item. id , & self . save_ctxt ) ;
1099
+ let id = id_from_node_id ( trait_item. id , & self . save_ctxt ) ;
1095
1100
1096
1101
self . dumper . dump_def (
1097
1102
& Access {
@@ -1105,7 +1110,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1105
1110
name,
1106
1111
qualname,
1107
1112
value : self . span . snippet ( trait_item. span ) ,
1108
- parent : Some ( :: id_from_def_id ( trait_id) ) ,
1113
+ parent : Some ( id_from_def_id ( trait_id) ) ,
1109
1114
children : vec ! [ ] ,
1110
1115
decl_id : None ,
1111
1116
docs : self . save_ctxt . docs_for_attrs ( & trait_item. attrs ) ,
@@ -1196,7 +1201,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1196
1201
// The parent def id of a given use tree is always the enclosing item.
1197
1202
let parent = self . save_ctxt . tcx . hir ( ) . opt_local_def_id ( id)
1198
1203
. and_then ( |id| self . save_ctxt . tcx . parent_def_id ( id) )
1199
- . map ( :: id_from_def_id) ;
1204
+ . map ( id_from_def_id) ;
1200
1205
1201
1206
match use_tree. kind {
1202
1207
ast:: UseTreeKind :: Simple ( alias, ..) => {
@@ -1212,7 +1217,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1212
1217
1213
1218
let sub_span = path. segments . last ( ) . unwrap ( ) . ident . span ;
1214
1219
if !self . span . filter_generated ( sub_span) {
1215
- let ref_id = self . lookup_def_id ( id) . map ( |id| :: id_from_def_id ( id) ) ;
1220
+ let ref_id = self . lookup_def_id ( id) . map ( |id| id_from_def_id ( id) ) ;
1216
1221
let alias_span = alias. map ( |i| self . span_from_span ( i. span ) ) ;
1217
1222
let span = self . span_from_span ( sub_span) ;
1218
1223
self . dumper . import ( & access, Import {
@@ -1298,10 +1303,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1298
1303
1299
1304
let cm = self . tcx . sess . source_map ( ) ;
1300
1305
let filename = cm. span_to_filename ( span) ;
1301
- let data_id = :: id_from_node_id ( id, & self . save_ctxt ) ;
1306
+ let data_id = id_from_node_id ( id, & self . save_ctxt ) ;
1302
1307
let children = m. items
1303
1308
. iter ( )
1304
- . map ( |i| :: id_from_node_id ( i. id , & self . save_ctxt ) )
1309
+ . map ( |i| id_from_node_id ( i. id , & self . save_ctxt ) )
1305
1310
. collect ( ) ;
1306
1311
let span = self . span_from_span ( span) ;
1307
1312
@@ -1345,7 +1350,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1345
1350
let span = self . span_from_span ( name_span) ;
1346
1351
let parent = self . save_ctxt . tcx . hir ( ) . opt_local_def_id ( item. id )
1347
1352
. and_then ( |id| self . save_ctxt . tcx . parent_def_id ( id) )
1348
- . map ( :: id_from_def_id) ;
1353
+ . map ( id_from_def_id) ;
1349
1354
self . dumper . import (
1350
1355
& Access {
1351
1356
public : false ,
@@ -1387,7 +1392,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1387
1392
let value = ty_to_string ( & ty) ;
1388
1393
if !self . span . filter_generated ( item. ident . span ) {
1389
1394
let span = self . span_from_span ( item. ident . span ) ;
1390
- let id = :: id_from_node_id ( item. id , & self . save_ctxt ) ;
1395
+ let id = id_from_node_id ( item. id , & self . save_ctxt ) ;
1391
1396
1392
1397
self . dumper . dump_def (
1393
1398
& access_from ! ( self . save_ctxt, item) ,
@@ -1417,7 +1422,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1417
1422
let value = String :: new ( ) ;
1418
1423
if !self . span . filter_generated ( item. ident . span ) {
1419
1424
let span = self . span_from_span ( item. ident . span ) ;
1420
- let id = :: id_from_node_id ( item. id , & self . save_ctxt ) ;
1425
+ let id = id_from_node_id ( item. id , & self . save_ctxt ) ;
1421
1426
1422
1427
self . dumper . dump_def (
1423
1428
& access_from ! ( self . save_ctxt, item) ,
@@ -1476,7 +1481,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1476
1481
self . dumper . dump_ref ( Ref {
1477
1482
kind : RefKind :: Type ,
1478
1483
span,
1479
- ref_id : :: id_from_def_id ( id) ,
1484
+ ref_id : id_from_def_id ( id) ,
1480
1485
} ) ;
1481
1486
}
1482
1487
0 commit comments