@@ -40,7 +40,7 @@ mod sig;
40
40
41
41
use rustc:: hir;
42
42
use rustc:: hir:: def:: Def as HirDef ;
43
- use rustc:: hir:: map:: { Node , NodeItem } ;
43
+ use rustc:: hir:: map:: { Node , NodeTraitItem , NodeImplItem } ;
44
44
use rustc:: hir:: def_id:: { DefId , LOCAL_CRATE } ;
45
45
use rustc:: middle:: cstore:: ExternCrate ;
46
46
use rustc:: session:: config:: CrateType :: CrateTypeExecutable ;
@@ -418,34 +418,30 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
418
418
Some ( impl_id) => match self . tcx . hir . get_if_local ( impl_id) {
419
419
Some ( Node :: NodeItem ( item) ) => match item. node {
420
420
hir:: ItemImpl ( .., ref ty, _) => {
421
- let mut result = String :: from ( "<" ) ;
422
- result . push_str ( & self . tcx . hir . node_to_pretty_string ( ty. id ) ) ;
421
+ let mut qualname = String :: from ( "<" ) ;
422
+ qualname . push_str ( & self . tcx . hir . node_to_pretty_string ( ty. id ) ) ;
423
423
424
424
let mut trait_id = self . tcx . trait_id_of_impl ( impl_id) ;
425
425
let mut decl_id = None ;
426
+ let mut docs = String :: new ( ) ;
427
+ let mut attrs = vec ! [ ] ;
428
+ if let Some ( NodeImplItem ( item) ) = self . tcx . hir . find ( id) {
429
+ docs = self . docs_for_attrs ( & item. attrs ) ;
430
+ attrs = item. attrs . to_vec ( ) ;
431
+ }
432
+
426
433
if let Some ( def_id) = trait_id {
427
- result. push_str ( " as " ) ;
428
- result. push_str ( & self . tcx . item_path_str ( def_id) ) ;
434
+ // A method in a trait impl.
435
+ qualname. push_str ( " as " ) ;
436
+ qualname. push_str ( & self . tcx . item_path_str ( def_id) ) ;
429
437
self . tcx
430
438
. associated_items ( def_id)
431
439
. find ( |item| item. name == name)
432
440
. map ( |item| decl_id = Some ( item. def_id ) ) ;
433
- } else {
434
- if let Some ( NodeItem ( item) ) = self . tcx . hir . find ( id) {
435
- if let hir:: ItemImpl ( _, _, _, _, _, ref ty, _) = item. node {
436
- trait_id = self . lookup_ref_id ( ty. id ) ;
437
- }
438
- }
439
441
}
440
- result. push_str ( ">" ) ;
441
-
442
- (
443
- result,
444
- trait_id,
445
- decl_id,
446
- self . docs_for_attrs ( & item. attrs ) ,
447
- item. attrs . to_vec ( ) ,
448
- )
442
+ qualname. push_str ( ">" ) ;
443
+
444
+ ( qualname, trait_id, decl_id, docs, attrs)
449
445
}
450
446
_ => {
451
447
span_bug ! (
@@ -467,25 +463,23 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
467
463
}
468
464
} ,
469
465
None => match self . tcx . trait_of_item ( self . tcx . hir . local_def_id ( id) ) {
470
- Some ( def_id) => match self . tcx . hir . get_if_local ( def_id) {
471
- Some ( Node :: NodeItem ( item) ) => (
466
+ Some ( def_id) => {
467
+ let mut docs = String :: new ( ) ;
468
+ let mut attrs = vec ! [ ] ;
469
+
470
+ if let Some ( NodeTraitItem ( item) ) = self . tcx . hir . find ( id) {
471
+ docs = self . docs_for_attrs ( & item. attrs ) ;
472
+ attrs = item. attrs . to_vec ( ) ;
473
+ }
474
+
475
+ (
472
476
format ! ( "::{}" , self . tcx. item_path_str( def_id) ) ,
473
477
Some ( def_id) ,
474
478
None ,
475
- self . docs_for_attrs ( & item. attrs ) ,
476
- item. attrs . to_vec ( ) ,
477
- ) ,
478
- r => {
479
- span_bug ! (
480
- span,
481
- "Could not find container {:?} for \
482
- method {}, got {:?}",
483
- def_id,
484
- id,
485
- r
486
- ) ;
487
- }
488
- } ,
479
+ docs,
480
+ attrs,
481
+ )
482
+ }
489
483
None => {
490
484
debug ! ( "Could not find container for method {} at {:?}" , id, span) ;
491
485
// This is not necessarily a bug, if there was a compilation error,
0 commit comments