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 (
@@ -433,12 +438,12 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
433438 & access_from ! ( self . save_ctxt, vis, id) ,
434439 Def {
435440 kind : DefKind :: Const ,
436- id : :: id_from_node_id ( id, & self . save_ctxt ) ,
441+ id : id_from_node_id ( id, & self . save_ctxt ) ,
437442 span,
438443 name : ident. name . to_string ( ) ,
439444 qualname,
440445 value : ty_to_string ( & typ) ,
441- parent : Some ( :: id_from_def_id ( parent_id) ) ,
446+ parent : Some ( id_from_def_id ( parent_id) ) ,
442447 children : vec ! [ ] ,
443448 decl_id : None ,
444449 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> {
495500 value,
496501 fields
497502 . 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 ) )
499504 . collect ( ) ,
500505 )
501506 }
@@ -508,7 +513,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
508513 & access_from ! ( self . save_ctxt, item) ,
509514 Def {
510515 kind,
511- id : :: id_from_node_id ( item. id , & self . save_ctxt ) ,
516+ id : id_from_node_id ( item. id , & self . save_ctxt ) ,
512517 span,
513518 name,
514519 qualname : qualname. clone ( ) ,
@@ -564,8 +569,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
564569 let value = format ! ( "{}::{} {{ {} }}" , enum_data. name, name, fields_str) ;
565570 if !self . span . filter_generated ( name_span) {
566571 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 ) ) ;
569574
570575 self . dumper . dump_def (
571576 & access,
@@ -602,8 +607,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
602607 }
603608 if !self . span . filter_generated ( name_span) {
604609 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 ) ) ;
607612
608613 self . dumper . dump_def (
609614 & access,
@@ -686,11 +691,11 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
686691 val. push_str ( & bounds_to_string ( trait_refs) ) ;
687692 }
688693 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 ) ;
690695 let span = self . span_from_span ( item. ident . span ) ;
691696 let children = methods
692697 . 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 ) )
694699 . collect ( ) ;
695700 self . dumper . dump_def (
696701 & access_from ! ( self . save_ctxt, item) ,
@@ -726,14 +731,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
726731 self . dumper . dump_ref ( Ref {
727732 kind : RefKind :: Type ,
728733 span : span. clone ( ) ,
729- ref_id : :: id_from_def_id ( id) ,
734+ ref_id : id_from_def_id ( id) ,
730735 } ) ;
731736
732737 self . dumper . dump_relation ( Relation {
733738 kind : RelationKind :: SuperTrait ,
734739 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 ) ,
737742 } ) ;
738743 }
739744 }
@@ -873,7 +878,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
873878 self . dumper . dump_ref ( Ref {
874879 kind : RefKind :: Variable ,
875880 span,
876- ref_id : :: id_from_def_id ( variant. fields [ index] . did ) ,
881+ ref_id : id_from_def_id ( variant. fields [ index] . did ) ,
877882 } ) ;
878883 }
879884 }
@@ -912,7 +917,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
912917
913918 if !self . span . filter_generated ( ident. span ) {
914919 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 ) ;
916921 let span = self . span_from_span ( ident. span ) ;
917922
918923 self . dumper . dump_def (
@@ -988,7 +993,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
988993 // Rust uses the id of the pattern for var lookups, so we'll use it too.
989994 if !self . span . filter_generated ( ident. span ) {
990995 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 ) ;
992997 let span = self . span_from_span ( ident. span ) ;
993998
994999 self . dumper . dump_def (
@@ -1091,7 +1096,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
10911096
10921097 if !self . span . filter_generated ( trait_item. ident . span ) {
10931098 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 ) ;
10951100
10961101 self . dumper . dump_def (
10971102 & Access {
@@ -1105,7 +1110,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
11051110 name,
11061111 qualname,
11071112 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) ) ,
11091114 children : vec ! [ ] ,
11101115 decl_id : None ,
11111116 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> {
11961201 // The parent def id of a given use tree is always the enclosing item.
11971202 let parent = self . save_ctxt . tcx . hir ( ) . opt_local_def_id ( id)
11981203 . and_then ( |id| self . save_ctxt . tcx . parent_def_id ( id) )
1199- . map ( :: id_from_def_id) ;
1204+ . map ( id_from_def_id) ;
12001205
12011206 match use_tree. kind {
12021207 ast:: UseTreeKind :: Simple ( alias, ..) => {
@@ -1212,7 +1217,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
12121217
12131218 let sub_span = path. segments . last ( ) . unwrap ( ) . ident . span ;
12141219 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) ) ;
12161221 let alias_span = alias. map ( |i| self . span_from_span ( i. span ) ) ;
12171222 let span = self . span_from_span ( sub_span) ;
12181223 self . dumper . import ( & access, Import {
@@ -1298,10 +1303,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
12981303
12991304 let cm = self . tcx . sess . source_map ( ) ;
13001305 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 ) ;
13021307 let children = m. items
13031308 . 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 ) )
13051310 . collect ( ) ;
13061311 let span = self . span_from_span ( span) ;
13071312
@@ -1345,7 +1350,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
13451350 let span = self . span_from_span ( name_span) ;
13461351 let parent = self . save_ctxt . tcx . hir ( ) . opt_local_def_id ( item. id )
13471352 . and_then ( |id| self . save_ctxt . tcx . parent_def_id ( id) )
1348- . map ( :: id_from_def_id) ;
1353+ . map ( id_from_def_id) ;
13491354 self . dumper . import (
13501355 & Access {
13511356 public : false ,
@@ -1387,7 +1392,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
13871392 let value = ty_to_string ( & ty) ;
13881393 if !self . span . filter_generated ( item. ident . span ) {
13891394 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 ) ;
13911396
13921397 self . dumper . dump_def (
13931398 & access_from ! ( self . save_ctxt, item) ,
@@ -1417,7 +1422,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
14171422 let value = String :: new ( ) ;
14181423 if !self . span . filter_generated ( item. ident . span ) {
14191424 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 ) ;
14211426
14221427 self . dumper . dump_def (
14231428 & access_from ! ( self . save_ctxt, item) ,
@@ -1476,7 +1481,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
14761481 self . dumper . dump_ref ( Ref {
14771482 kind : RefKind :: Type ,
14781483 span,
1479- ref_id : :: id_from_def_id ( id) ,
1484+ ref_id : id_from_def_id ( id) ,
14801485 } ) ;
14811486 }
14821487
0 commit comments