27
27
//! is used for recording the output in a format-agnostic way (see CsvDumper
28
28
//! for an example).
29
29
30
+ use rustc:: hir;
30
31
use rustc:: hir:: def:: Def ;
31
32
use rustc:: hir:: def_id:: DefId ;
32
- use rustc:: hir:: map:: Node ;
33
+ use rustc:: hir:: map:: { Node , NodeItem } ;
33
34
use rustc:: session:: Session ;
34
35
use rustc:: ty:: { self , TyCtxt , ImplOrTraitItem , ImplOrTraitItemContainer } ;
35
36
@@ -47,7 +48,7 @@ use syntax_pos::*;
47
48
use super :: { escape, generated_code, SaveContext , PathCollector , docs_for_attrs} ;
48
49
use super :: data:: * ;
49
50
use super :: dump:: Dump ;
50
- use super :: external_data:: Lower ;
51
+ use super :: external_data:: { Lower , make_def_id } ;
51
52
use super :: span_utils:: SpanUtils ;
52
53
use super :: recorder;
53
54
@@ -271,11 +272,13 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
271
272
272
273
// looks up anything, not just a type
273
274
fn lookup_type_ref ( & self , ref_id : NodeId ) -> Option < DefId > {
274
- match self . tcx . expect_def ( ref_id) {
275
- Def :: PrimTy ( ..) => None ,
276
- Def :: SelfTy ( ..) => None ,
277
- def => Some ( def. def_id ( ) ) ,
278
- }
275
+ self . tcx . expect_def_or_none ( ref_id) . and_then ( |def| {
276
+ match def {
277
+ Def :: PrimTy ( ..) => None ,
278
+ Def :: SelfTy ( ..) => None ,
279
+ def => Some ( def. def_id ( ) ) ,
280
+ }
281
+ } )
279
282
}
280
283
281
284
fn process_def_kind ( & mut self ,
@@ -399,20 +402,36 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
399
402
if !self . span . filter_generated ( Some ( method_data. span ) , span) {
400
403
let container =
401
404
self . tcx . impl_or_trait_item ( self . tcx . map . local_def_id ( id) ) . container ( ) ;
402
- let decl_id = if let ImplOrTraitItemContainer :: ImplContainer ( id) = container {
403
- self . tcx . trait_id_of_impl ( id) . and_then ( |id| {
404
- for item in & * * self . tcx . trait_items ( id) {
405
- if let & ImplOrTraitItem :: MethodTraitItem ( ref m) = item {
406
- if m. name == name {
407
- return Some ( m. def_id ) ;
405
+ let mut trait_id;
406
+ let mut decl_id = None ;
407
+ match container {
408
+ ImplOrTraitItemContainer :: ImplContainer ( id) => {
409
+ trait_id = self . tcx . trait_id_of_impl ( id) ;
410
+
411
+ match trait_id {
412
+ Some ( id) => {
413
+ for item in & * * self . tcx . trait_items ( id) {
414
+ if let & ImplOrTraitItem :: MethodTraitItem ( ref m) = item {
415
+ if m. name == name {
416
+ decl_id = Some ( m. def_id ) ;
417
+ break ;
418
+ }
419
+ }
420
+ }
421
+ }
422
+ None => {
423
+ if let Some ( NodeItem ( item) ) = self . tcx . map . get_if_local ( id) {
424
+ if let hir:: ItemImpl ( _, _, _, _, ref ty, _) = item. node {
425
+ trait_id = self . lookup_type_ref ( ty. id ) ;
426
+ }
408
427
}
409
428
}
410
429
}
411
- None
412
- } )
413
- } else {
414
- None
415
- } ;
430
+ }
431
+ ImplOrTraitItemContainer :: TraitContainer ( id ) => {
432
+ trait_id = Some ( id ) ;
433
+ }
434
+ }
416
435
417
436
self . dumper . method ( MethodData {
418
437
id : method_data. id ,
@@ -422,6 +441,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
422
441
qualname : method_data. qualname . clone ( ) ,
423
442
value : sig_str,
424
443
decl_id : decl_id,
444
+ parent : trait_id,
425
445
visibility : vis,
426
446
docs : docs_for_attrs ( attrs) ,
427
447
} . lower ( self . tcx ) ) ;
@@ -544,7 +564,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
544
564
span : Span ,
545
565
typ : & ast:: Ty ,
546
566
expr : & ast:: Expr ,
547
- parent_id : NodeId ,
567
+ parent_id : DefId ,
548
568
vis : Visibility ,
549
569
attrs : & [ Attribute ] ) {
550
570
let qualname = format ! ( "::{}" , self . tcx. node_path_str( id) ) ;
@@ -659,7 +679,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
659
679
type_value : enum_data. qualname . clone ( ) ,
660
680
value : val,
661
681
scope : enum_data. scope ,
662
- parent : Some ( item. id ) ,
682
+ parent : Some ( make_def_id ( item. id , & self . tcx . map ) ) ,
663
683
docs : docs_for_attrs ( & variant. node . attrs ) ,
664
684
} . lower ( self . tcx ) ) ;
665
685
}
@@ -684,7 +704,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
684
704
type_value : enum_data. qualname . clone ( ) ,
685
705
value : val,
686
706
scope : enum_data. scope ,
687
- parent : Some ( item. id ) ,
707
+ parent : Some ( make_def_id ( item. id , & self . tcx . map ) ) ,
688
708
docs : docs_for_attrs ( & variant. node . attrs ) ,
689
709
} . lower ( self . tcx ) ) ;
690
710
}
@@ -738,7 +758,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
738
758
}
739
759
self . process_generic_params ( type_parameters, item. span , "" , item. id ) ;
740
760
for impl_item in impl_items {
741
- self . process_impl_item ( impl_item, item. id ) ;
761
+ let map = & self . tcx . map ;
762
+ self . process_impl_item ( impl_item, make_def_id ( item. id , map) ) ;
742
763
}
743
764
}
744
765
@@ -809,7 +830,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
809
830
// walk generics and methods
810
831
self . process_generic_params ( generics, item. span , & qualname, item. id ) ;
811
832
for method in methods {
812
- self . process_trait_item ( method, item. id )
833
+ let map = & self . tcx . map ;
834
+ self . process_trait_item ( method, make_def_id ( item. id , map) )
813
835
}
814
836
}
815
837
@@ -1076,7 +1098,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
1076
1098
}
1077
1099
}
1078
1100
1079
- fn process_trait_item ( & mut self , trait_item : & ast:: TraitItem , trait_id : NodeId ) {
1101
+ fn process_trait_item ( & mut self , trait_item : & ast:: TraitItem , trait_id : DefId ) {
1080
1102
self . process_macro_use ( trait_item. span , trait_item. id ) ;
1081
1103
match trait_item. node {
1082
1104
ast:: TraitItemKind :: Const ( ref ty, Some ( ref expr) ) => {
@@ -1104,7 +1126,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
1104
1126
}
1105
1127
}
1106
1128
1107
- fn process_impl_item ( & mut self , impl_item : & ast:: ImplItem , impl_id : NodeId ) {
1129
+ fn process_impl_item ( & mut self , impl_item : & ast:: ImplItem , impl_id : DefId ) {
1108
1130
self . process_macro_use ( impl_item. span , impl_item. id ) ;
1109
1131
match impl_item. node {
1110
1132
ast:: ImplItemKind :: Const ( ref ty, ref expr) => {
0 commit comments