1616use rustc:: hir:: def:: Def as HirDef ;
1717use rustc:: hir:: def_id:: DefId ;
1818use rustc:: session:: config:: Input ;
19+ use rustc:: span_bug;
1920use rustc:: ty:: { self , TyCtxt } ;
2021use rustc_data_structures:: fx:: FxHashSet ;
2122
@@ -32,16 +33,20 @@ use syntax::print::pprust::{
3233} ;
3334use syntax:: ptr:: P ;
3435use syntax:: source_map:: { Spanned , DUMMY_SP , respan} ;
36+ use syntax:: walk_list;
3537use syntax_pos:: * ;
3638
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;
4144
4245use rls_data:: { CompilationOptions , CratePreludeData , Def , DefKind , GlobalCrateId , Import ,
4346 ImportKind , Ref , RefKind , Relation , RelationKind , SpanData } ;
4447
48+ use log:: { debug, error} ;
49+
4550macro_rules! down_cast_data {
4651 ( $id: ident, $kind: ident, $sp: expr) => {
4752 let $id = if let super :: Data :: $kind( data) = $id {
@@ -68,7 +73,7 @@ macro_rules! access_from {
6873 } ;
6974}
7075
71- pub struct DumpVisitor < ' l , ' tcx : ' l , ' ll , O : DumpOutput + ' ll > {
76+ pub struct DumpVisitor < ' l , ' tcx : ' l , ' ll , O : DumpOutput > {
7277 save_ctxt : SaveContext < ' l , ' tcx > ,
7378 tcx : TyCtxt < ' l , ' tcx , ' tcx > ,
7479 dumper : & ' ll mut JsonDumper < O > ,
@@ -245,7 +250,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
245250 None => continue ,
246251 } ;
247252 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 ) ;
249254 let span = self . span_from_span ( ident. span ) ;
250255
251256 self . dumper . dump_def (
@@ -286,7 +291,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
286291 debug ! ( "process_method: {}:{}" , id, ident) ;
287292
288293 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) ;
290295 if body. is_some ( ) {
291296 self . nest_tables (
292297 id,
@@ -339,7 +344,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
339344 // Append $id to name to make sure each one is unique.
340345 let qualname = format ! ( "{}::{}${}" , prefix, name, id) ;
341346 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 ) ;
343348 let span = self . span_from_span ( param_ss) ;
344349
345350 self . dumper . dump_def (
@@ -434,12 +439,12 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
434439 & access_from ! ( self . save_ctxt, vis, id) ,
435440 Def {
436441 kind : DefKind :: Const ,
437- id : :: id_from_node_id ( id, & self . save_ctxt ) ,
442+ id : id_from_node_id ( id, & self . save_ctxt ) ,
438443 span,
439444 name : ident. name . to_string ( ) ,
440445 qualname,
441446 value : ty_to_string ( & typ) ,
442- parent : Some ( :: id_from_def_id ( parent_id) ) ,
447+ parent : Some ( id_from_def_id ( parent_id) ) ,
443448 children : vec ! [ ] ,
444449 decl_id : None ,
445450 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> {
496501 value,
497502 fields
498503 . 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 ) )
500505 . collect ( ) ,
501506 )
502507 }
@@ -509,7 +514,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
509514 & access_from ! ( self . save_ctxt, item) ,
510515 Def {
511516 kind,
512- id : :: id_from_node_id ( item. id , & self . save_ctxt ) ,
517+ id : id_from_node_id ( item. id , & self . save_ctxt ) ,
513518 span,
514519 name,
515520 qualname : qualname. clone ( ) ,
@@ -565,8 +570,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
565570 let value = format ! ( "{}::{} {{ {} }}" , enum_data. name, name, fields_str) ;
566571 if !self . span . filter_generated ( name_span) {
567572 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 ) ) ;
570575
571576 self . dumper . dump_def (
572577 & access,
@@ -603,8 +608,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
603608 }
604609 if !self . span . filter_generated ( name_span) {
605610 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 ) ) ;
608613
609614 self . dumper . dump_def (
610615 & access,
@@ -687,11 +692,11 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
687692 val. push_str ( & bounds_to_string ( trait_refs) ) ;
688693 }
689694 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 ) ;
691696 let span = self . span_from_span ( item. ident . span ) ;
692697 let children = methods
693698 . 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 ) )
695700 . collect ( ) ;
696701 self . dumper . dump_def (
697702 & access_from ! ( self . save_ctxt, item) ,
@@ -727,14 +732,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
727732 self . dumper . dump_ref ( Ref {
728733 kind : RefKind :: Type ,
729734 span : span. clone ( ) ,
730- ref_id : :: id_from_def_id ( id) ,
735+ ref_id : id_from_def_id ( id) ,
731736 } ) ;
732737
733738 self . dumper . dump_relation ( Relation {
734739 kind : RelationKind :: SuperTrait ,
735740 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 ) ,
738743 } ) ;
739744 }
740745 }
@@ -874,7 +879,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
874879 self . dumper . dump_ref ( Ref {
875880 kind : RefKind :: Variable ,
876881 span,
877- ref_id : :: id_from_def_id ( variant. fields [ index] . did ) ,
882+ ref_id : id_from_def_id ( variant. fields [ index] . did ) ,
878883 } ) ;
879884 }
880885 }
@@ -913,7 +918,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
913918
914919 if !self . span . filter_generated ( ident. span ) {
915920 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 ) ;
917922 let span = self . span_from_span ( ident. span ) ;
918923
919924 self . dumper . dump_def (
@@ -989,7 +994,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
989994 // Rust uses the id of the pattern for var lookups, so we'll use it too.
990995 if !self . span . filter_generated ( ident. span ) {
991996 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 ) ;
993998 let span = self . span_from_span ( ident. span ) ;
994999
9951000 self . dumper . dump_def (
@@ -1092,7 +1097,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
10921097
10931098 if !self . span . filter_generated ( trait_item. ident . span ) {
10941099 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 ) ;
10961101
10971102 self . dumper . dump_def (
10981103 & Access {
@@ -1106,7 +1111,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
11061111 name,
11071112 qualname,
11081113 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) ) ,
11101115 children : vec ! [ ] ,
11111116 decl_id : None ,
11121117 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> {
11971202 // The parent def id of a given use tree is always the enclosing item.
11981203 let parent = self . save_ctxt . tcx . hir ( ) . opt_local_def_id ( id)
11991204 . and_then ( |id| self . save_ctxt . tcx . parent_def_id ( id) )
1200- . map ( :: id_from_def_id) ;
1205+ . map ( id_from_def_id) ;
12011206
12021207 match use_tree. kind {
12031208 ast:: UseTreeKind :: Simple ( alias, ..) => {
@@ -1213,7 +1218,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
12131218
12141219 let sub_span = path. segments . last ( ) . unwrap ( ) . ident . span ;
12151220 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) ) ;
12171222 let alias_span = alias. map ( |i| self . span_from_span ( i. span ) ) ;
12181223 let span = self . span_from_span ( sub_span) ;
12191224 self . dumper . import ( & access, Import {
@@ -1299,10 +1304,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
12991304
13001305 let cm = self . tcx . sess . source_map ( ) ;
13011306 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 ) ;
13031308 let children = m. items
13041309 . 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 ) )
13061311 . collect ( ) ;
13071312 let span = self . span_from_span ( span) ;
13081313
@@ -1346,7 +1351,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
13461351 let span = self . span_from_span ( name_span) ;
13471352 let parent = self . save_ctxt . tcx . hir ( ) . opt_local_def_id ( item. id )
13481353 . and_then ( |id| self . save_ctxt . tcx . parent_def_id ( id) )
1349- . map ( :: id_from_def_id) ;
1354+ . map ( id_from_def_id) ;
13501355 self . dumper . import (
13511356 & Access {
13521357 public : false ,
@@ -1388,7 +1393,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
13881393 let value = ty_to_string ( & ty) ;
13891394 if !self . span . filter_generated ( item. ident . span ) {
13901395 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 ) ;
13921397
13931398 self . dumper . dump_def (
13941399 & access_from ! ( self . save_ctxt, item) ,
@@ -1418,7 +1423,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
14181423 let value = String :: new ( ) ;
14191424 if !self . span . filter_generated ( item. ident . span ) {
14201425 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 ) ;
14221427
14231428 self . dumper . dump_def (
14241429 & access_from ! ( self . save_ctxt, item) ,
@@ -1484,7 +1489,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
14841489 self . dumper . dump_ref ( Ref {
14851490 kind : RefKind :: Type ,
14861491 span,
1487- ref_id : :: id_from_def_id ( id) ,
1492+ ref_id : id_from_def_id ( id) ,
14881493 } ) ;
14891494 }
14901495
0 commit comments