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 (
@@ -434,12 +439,12 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
434
439
& access_from ! ( self . save_ctxt, vis, id) ,
435
440
Def {
436
441
kind : DefKind :: Const ,
437
- id : :: id_from_node_id ( id, & self . save_ctxt ) ,
442
+ id : id_from_node_id ( id, & self . save_ctxt ) ,
438
443
span,
439
444
name : ident. name . to_string ( ) ,
440
445
qualname,
441
446
value : ty_to_string ( & typ) ,
442
- parent : Some ( :: id_from_def_id ( parent_id) ) ,
447
+ parent : Some ( id_from_def_id ( parent_id) ) ,
443
448
children : vec ! [ ] ,
444
449
decl_id : None ,
445
450
docs : self . save_ctxt . docs_for_attrs ( attrs) ,
@@ -496,7 +501,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
496
501
value,
497
502
fields
498
503
. iter ( )
499
- . map ( |f| :: id_from_node_id ( f. id , & self . save_ctxt ) )
504
+ . map ( |f| id_from_node_id ( f. id , & self . save_ctxt ) )
500
505
. collect ( ) ,
501
506
)
502
507
}
@@ -509,7 +514,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
509
514
& access_from ! ( self . save_ctxt, item) ,
510
515
Def {
511
516
kind,
512
- id : :: id_from_node_id ( item. id , & self . save_ctxt ) ,
517
+ id : id_from_node_id ( item. id , & self . save_ctxt ) ,
513
518
span,
514
519
name,
515
520
qualname : qualname. clone ( ) ,
@@ -565,8 +570,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
565
570
let value = format ! ( "{}::{} {{ {} }}" , enum_data. name, name, fields_str) ;
566
571
if !self . span . filter_generated ( name_span) {
567
572
let span = self . span_from_span ( name_span) ;
568
- let id = :: id_from_node_id ( variant. node . data . id ( ) , & self . save_ctxt ) ;
569
- let parent = Some ( :: id_from_node_id ( item. id , & self . save_ctxt ) ) ;
573
+ let id = id_from_node_id ( variant. node . data . id ( ) , & self . save_ctxt ) ;
574
+ let parent = Some ( id_from_node_id ( item. id , & self . save_ctxt ) ) ;
570
575
571
576
self . dumper . dump_def (
572
577
& access,
@@ -603,8 +608,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
603
608
}
604
609
if !self . span . filter_generated ( name_span) {
605
610
let span = self . span_from_span ( name_span) ;
606
- let id = :: id_from_node_id ( variant. node . data . id ( ) , & self . save_ctxt ) ;
607
- let parent = Some ( :: id_from_node_id ( item. id , & self . save_ctxt ) ) ;
611
+ let id = id_from_node_id ( variant. node . data . id ( ) , & self . save_ctxt ) ;
612
+ let parent = Some ( id_from_node_id ( item. id , & self . save_ctxt ) ) ;
608
613
609
614
self . dumper . dump_def (
610
615
& access,
@@ -687,11 +692,11 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
687
692
val. push_str ( & bounds_to_string ( trait_refs) ) ;
688
693
}
689
694
if !self . span . filter_generated ( item. ident . span ) {
690
- let id = :: id_from_node_id ( item. id , & self . save_ctxt ) ;
695
+ let id = id_from_node_id ( item. id , & self . save_ctxt ) ;
691
696
let span = self . span_from_span ( item. ident . span ) ;
692
697
let children = methods
693
698
. iter ( )
694
- . map ( |i| :: id_from_node_id ( i. id , & self . save_ctxt ) )
699
+ . map ( |i| id_from_node_id ( i. id , & self . save_ctxt ) )
695
700
. collect ( ) ;
696
701
self . dumper . dump_def (
697
702
& access_from ! ( self . save_ctxt, item) ,
@@ -727,14 +732,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
727
732
self . dumper . dump_ref ( Ref {
728
733
kind : RefKind :: Type ,
729
734
span : span. clone ( ) ,
730
- ref_id : :: id_from_def_id ( id) ,
735
+ ref_id : id_from_def_id ( id) ,
731
736
} ) ;
732
737
733
738
self . dumper . dump_relation ( Relation {
734
739
kind : RelationKind :: SuperTrait ,
735
740
span,
736
- from : :: id_from_def_id ( id) ,
737
- to : :: id_from_node_id ( item. id , & self . save_ctxt ) ,
741
+ from : id_from_def_id ( id) ,
742
+ to : id_from_node_id ( item. id , & self . save_ctxt ) ,
738
743
} ) ;
739
744
}
740
745
}
@@ -874,7 +879,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
874
879
self . dumper . dump_ref ( Ref {
875
880
kind : RefKind :: Variable ,
876
881
span,
877
- ref_id : :: id_from_def_id ( variant. fields [ index] . did ) ,
882
+ ref_id : id_from_def_id ( variant. fields [ index] . did ) ,
878
883
} ) ;
879
884
}
880
885
}
@@ -913,7 +918,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
913
918
914
919
if !self . span . filter_generated ( ident. span ) {
915
920
let qualname = format ! ( "{}${}" , ident. to_string( ) , id) ;
916
- let id = :: id_from_node_id ( id, & self . save_ctxt ) ;
921
+ let id = id_from_node_id ( id, & self . save_ctxt ) ;
917
922
let span = self . span_from_span ( ident. span ) ;
918
923
919
924
self . dumper . dump_def (
@@ -989,7 +994,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
989
994
// Rust uses the id of the pattern for var lookups, so we'll use it too.
990
995
if !self . span . filter_generated ( ident. span ) {
991
996
let qualname = format ! ( "{}${}" , ident. to_string( ) , id) ;
992
- let id = :: id_from_node_id ( id, & self . save_ctxt ) ;
997
+ let id = id_from_node_id ( id, & self . save_ctxt ) ;
993
998
let span = self . span_from_span ( ident. span ) ;
994
999
995
1000
self . dumper . dump_def (
@@ -1092,7 +1097,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1092
1097
1093
1098
if !self . span . filter_generated ( trait_item. ident . span ) {
1094
1099
let span = self . span_from_span ( trait_item. ident . span ) ;
1095
- let id = :: id_from_node_id ( trait_item. id , & self . save_ctxt ) ;
1100
+ let id = id_from_node_id ( trait_item. id , & self . save_ctxt ) ;
1096
1101
1097
1102
self . dumper . dump_def (
1098
1103
& Access {
@@ -1106,7 +1111,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1106
1111
name,
1107
1112
qualname,
1108
1113
value : self . span . snippet ( trait_item. span ) ,
1109
- parent : Some ( :: id_from_def_id ( trait_id) ) ,
1114
+ parent : Some ( id_from_def_id ( trait_id) ) ,
1110
1115
children : vec ! [ ] ,
1111
1116
decl_id : None ,
1112
1117
docs : self . save_ctxt . docs_for_attrs ( & trait_item. attrs ) ,
@@ -1197,7 +1202,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1197
1202
// The parent def id of a given use tree is always the enclosing item.
1198
1203
let parent = self . save_ctxt . tcx . hir ( ) . opt_local_def_id ( id)
1199
1204
. and_then ( |id| self . save_ctxt . tcx . parent_def_id ( id) )
1200
- . map ( :: id_from_def_id) ;
1205
+ . map ( id_from_def_id) ;
1201
1206
1202
1207
match use_tree. kind {
1203
1208
ast:: UseTreeKind :: Simple ( alias, ..) => {
@@ -1213,7 +1218,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1213
1218
1214
1219
let sub_span = path. segments . last ( ) . unwrap ( ) . ident . span ;
1215
1220
if !self . span . filter_generated ( sub_span) {
1216
- let ref_id = self . lookup_def_id ( id) . map ( |id| :: id_from_def_id ( id) ) ;
1221
+ let ref_id = self . lookup_def_id ( id) . map ( |id| id_from_def_id ( id) ) ;
1217
1222
let alias_span = alias. map ( |i| self . span_from_span ( i. span ) ) ;
1218
1223
let span = self . span_from_span ( sub_span) ;
1219
1224
self . dumper . import ( & access, Import {
@@ -1299,10 +1304,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1299
1304
1300
1305
let cm = self . tcx . sess . source_map ( ) ;
1301
1306
let filename = cm. span_to_filename ( span) ;
1302
- let data_id = :: id_from_node_id ( id, & self . save_ctxt ) ;
1307
+ let data_id = id_from_node_id ( id, & self . save_ctxt ) ;
1303
1308
let children = m. items
1304
1309
. iter ( )
1305
- . map ( |i| :: id_from_node_id ( i. id , & self . save_ctxt ) )
1310
+ . map ( |i| id_from_node_id ( i. id , & self . save_ctxt ) )
1306
1311
. collect ( ) ;
1307
1312
let span = self . span_from_span ( span) ;
1308
1313
@@ -1346,7 +1351,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1346
1351
let span = self . span_from_span ( name_span) ;
1347
1352
let parent = self . save_ctxt . tcx . hir ( ) . opt_local_def_id ( item. id )
1348
1353
. and_then ( |id| self . save_ctxt . tcx . parent_def_id ( id) )
1349
- . map ( :: id_from_def_id) ;
1354
+ . map ( id_from_def_id) ;
1350
1355
self . dumper . import (
1351
1356
& Access {
1352
1357
public : false ,
@@ -1388,7 +1393,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1388
1393
let value = ty_to_string ( & ty) ;
1389
1394
if !self . span . filter_generated ( item. ident . span ) {
1390
1395
let span = self . span_from_span ( item. ident . span ) ;
1391
- let id = :: id_from_node_id ( item. id , & self . save_ctxt ) ;
1396
+ let id = id_from_node_id ( item. id , & self . save_ctxt ) ;
1392
1397
1393
1398
self . dumper . dump_def (
1394
1399
& access_from ! ( self . save_ctxt, item) ,
@@ -1418,7 +1423,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1418
1423
let value = String :: new ( ) ;
1419
1424
if !self . span . filter_generated ( item. ident . span ) {
1420
1425
let span = self . span_from_span ( item. ident . span ) ;
1421
- let id = :: id_from_node_id ( item. id , & self . save_ctxt ) ;
1426
+ let id = id_from_node_id ( item. id , & self . save_ctxt ) ;
1422
1427
1423
1428
self . dumper . dump_def (
1424
1429
& access_from ! ( self . save_ctxt, item) ,
@@ -1484,7 +1489,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1484
1489
self . dumper . dump_ref ( Ref {
1485
1490
kind : RefKind :: Type ,
1486
1491
span,
1487
- ref_id : :: id_from_def_id ( id) ,
1492
+ ref_id : id_from_def_id ( id) ,
1488
1493
} ) ;
1489
1494
}
1490
1495
0 commit comments