30
30
use rustc:: hir:: def:: Def ;
31
31
use rustc:: hir:: def_id:: DefId ;
32
32
use rustc:: session:: Session ;
33
- use rustc:: ty:: { self , TyCtxt } ;
33
+ use rustc:: ty:: { self , TyCtxt , ImplOrTraitItem , ImplOrTraitItemContainer } ;
34
34
35
35
use std:: collections:: HashSet ;
36
36
use std:: hash:: * ;
@@ -356,6 +356,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
356
356
if !self . span . filter_generated ( sub_span, p. span ) {
357
357
self . dumper . variable ( VariableData {
358
358
id : id,
359
+ kind : VariableKind :: Local ,
359
360
span : sub_span. expect ( "No span found for variable" ) ,
360
361
name : path_to_string ( p) ,
361
362
qualname : format ! ( "{}::{}" , qualname, path_to_string( p) ) ,
@@ -380,24 +381,42 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
380
381
381
382
let sig_str = :: make_signature ( & sig. decl , & sig. generics ) ;
382
383
if body. is_some ( ) {
383
- if !self . span . filter_generated ( Some ( method_data. span ) , span) {
384
- let mut data = method_data. clone ( ) ;
385
- data. value = sig_str;
386
- self . dumper . function ( data. lower ( self . tcx ) ) ;
387
- }
388
384
self . process_formals ( & sig. decl . inputs , & method_data. qualname ) ;
389
- } else {
390
- if !self . span . filter_generated ( Some ( method_data. span ) , span) {
391
- self . dumper . method ( MethodData {
392
- id : method_data. id ,
393
- name : method_data. name ,
394
- span : method_data. span ,
395
- scope : method_data. scope ,
396
- qualname : method_data. qualname . clone ( ) ,
397
- value : sig_str,
398
- } . lower ( self . tcx ) ) ;
399
- }
400
385
}
386
+
387
+ // If the method is defined in an impl, then try and find the corresponding
388
+ // method decl in a trait, and if there is one, make a decl_id for it. This
389
+ // requires looking up the impl, then the trait, then searching for a method
390
+ // with the right name.
391
+ if !self . span . filter_generated ( Some ( method_data. span ) , span) {
392
+ let container =
393
+ self . tcx . impl_or_trait_item ( self . tcx . map . local_def_id ( id) ) . container ( ) ;
394
+ let decl_id = if let ImplOrTraitItemContainer :: ImplContainer ( id) = container {
395
+ self . tcx . trait_id_of_impl ( id) . and_then ( |id| {
396
+ for item in & * * self . tcx . trait_items ( id) {
397
+ if let & ImplOrTraitItem :: MethodTraitItem ( ref m) = item {
398
+ if m. name == name {
399
+ return Some ( m. def_id ) ;
400
+ }
401
+ }
402
+ }
403
+ None
404
+ } )
405
+ } else {
406
+ None
407
+ } ;
408
+
409
+ self . dumper . method ( MethodData {
410
+ id : method_data. id ,
411
+ name : method_data. name ,
412
+ span : method_data. span ,
413
+ scope : method_data. scope ,
414
+ qualname : method_data. qualname . clone ( ) ,
415
+ value : sig_str,
416
+ decl_id : decl_id,
417
+ } . lower ( self . tcx ) ) ;
418
+ }
419
+
401
420
self . process_generic_params ( & sig. generics , span, & method_data. qualname , id) ;
402
421
}
403
422
@@ -519,6 +538,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
519
538
if !self . span . filter_generated ( sub_span, span) {
520
539
self . dumper . variable ( VariableData {
521
540
span : sub_span. expect ( "No span found for variable" ) ,
541
+ kind : VariableKind :: Const ,
522
542
id : id,
523
543
name : name. to_string ( ) ,
524
544
qualname : qualname,
@@ -542,17 +562,18 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
542
562
let qualname = format ! ( "::{}" , self . tcx. node_path_str( item. id) ) ;
543
563
544
564
let sub_span = self . span . sub_span_after_keyword ( item. span , keywords:: Struct ) ;
545
- let val = if let ast:: ItemKind :: Struct ( ast:: VariantData :: Struct ( ref fields, _) , _) =
546
- item. node {
565
+ let ( val, fields) =
566
+ if let ast:: ItemKind :: Struct ( ast:: VariantData :: Struct ( ref fields, _) , _) = item. node
567
+ {
547
568
let fields_str = fields. iter ( )
548
569
. enumerate ( )
549
570
. map ( |( i, f) | f. ident . map ( |i| i. to_string ( ) )
550
571
. unwrap_or ( i. to_string ( ) ) )
551
572
. collect :: < Vec < _ > > ( )
552
573
. join ( ", " ) ;
553
- format ! ( "{} {{ {} }}" , name, fields_str)
574
+ ( format ! ( "{} {{ {} }}" , name, fields_str) , fields . iter ( ) . map ( |f| f . id ) . collect ( ) )
554
575
} else {
555
- String :: new ( )
576
+ ( String :: new ( ) , vec ! [ ] )
556
577
} ;
557
578
558
579
if !self . span . filter_generated ( sub_span, item. span ) {
@@ -563,7 +584,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
563
584
ctor_id : def. id ( ) ,
564
585
qualname : qualname. clone ( ) ,
565
586
scope : self . cur_scope ,
566
- value : val
587
+ value : val,
588
+ fields : fields,
567
589
} . lower ( self . tcx ) ) ;
568
590
}
569
591
@@ -718,7 +740,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
718
740
name : name,
719
741
qualname : qualname. clone ( ) ,
720
742
scope : self . cur_scope ,
721
- value : val
743
+ value : val,
744
+ items : methods. iter ( ) . map ( |i| i. id ) . collect ( ) ,
722
745
} . lower ( self . tcx ) ) ;
723
746
}
724
747
@@ -958,6 +981,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
958
981
if !self . span . filter_generated ( sub_span, p. span ) {
959
982
self . dumper . variable ( VariableData {
960
983
span : sub_span. expect ( "No span found for variable" ) ,
984
+ kind : VariableKind :: Local ,
961
985
id : id,
962
986
name : path_to_string ( p) ,
963
987
qualname : format ! ( "{}${}" , path_to_string( p) , id) ,
@@ -1366,6 +1390,7 @@ impl<'v, 'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'v> for DumpVisitor<'l, 'tcx,
1366
1390
if !self . span . filter_generated ( Some ( p. span ) , p. span ) {
1367
1391
self . dumper . variable ( VariableData {
1368
1392
span : p. span ,
1393
+ kind : VariableKind :: Local ,
1369
1394
id : id,
1370
1395
name : path_to_string ( p) ,
1371
1396
qualname : format ! ( "{}${}" , path_to_string( p) , id) ,
0 commit comments