@@ -82,7 +82,6 @@ use rustc_hir::{
82
82
TraitItemKind , TraitRef , TyKind , UnOp , ArrayLen
83
83
} ;
84
84
use rustc_lint:: { LateContext , Level , Lint , LintContext } ;
85
- use rustc_middle:: hir:: exports:: Export ;
86
85
use rustc_middle:: hir:: map:: Map ;
87
86
use rustc_middle:: hir:: place:: PlaceBase ;
88
87
use rustc_middle:: ty as rustc_ty;
@@ -523,10 +522,21 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
523
522
}
524
523
} ;
525
524
}
526
- fn item_child_by_name < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId , name : & str ) -> Option < & ' tcx Export > {
527
- tcx. item_children ( def_id)
528
- . iter ( )
529
- . find ( |item| item. ident . name . as_str ( ) == name)
525
+ fn item_child_by_name < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId , name : & str ) -> Option < Res > {
526
+ match tcx. def_kind ( def_id) {
527
+ DefKind :: Mod | DefKind :: Enum | DefKind :: Trait => tcx
528
+ . item_children ( def_id)
529
+ . iter ( )
530
+ . find ( |item| item. ident . name . as_str ( ) == name)
531
+ . map ( |child| child. res . expect_non_local ( ) ) ,
532
+ DefKind :: Impl => tcx
533
+ . associated_item_def_ids ( def_id)
534
+ . iter ( )
535
+ . copied ( )
536
+ . find ( |assoc_def_id| tcx. item_name ( * assoc_def_id) . as_str ( ) == name)
537
+ . map ( |assoc_def_id| Res :: Def ( tcx. def_kind ( assoc_def_id) , assoc_def_id) ) ,
538
+ _ => None ,
539
+ }
530
540
}
531
541
532
542
let ( krate, first, path) = match * path {
@@ -543,15 +553,12 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
543
553
let last = path
544
554
. iter ( )
545
555
. copied ( )
546
- // `get_def_path` seems to generate these empty segments for extern blocks.
547
- // We can just ignore them.
548
- . filter ( |segment| !segment. is_empty ( ) )
549
556
// for each segment, find the child item
550
- . try_fold ( first, |item , segment| {
551
- let def_id = item . res . def_id ( ) ;
557
+ . try_fold ( first, |res , segment| {
558
+ let def_id = res. def_id ( ) ;
552
559
if let Some ( item) = item_child_by_name ( tcx, def_id, segment) {
553
560
Some ( item)
554
- } else if matches ! ( item . res, Res :: Def ( DefKind :: Enum | DefKind :: Struct , _) ) {
561
+ } else if matches ! ( res, Res :: Def ( DefKind :: Enum | DefKind :: Struct , _) ) {
555
562
// it is not a child item so check inherent impl items
556
563
tcx. inherent_impls ( def_id)
557
564
. iter ( )
@@ -560,7 +567,7 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
560
567
None
561
568
}
562
569
} ) ;
563
- try_res ! ( last) . res . expect_non_local ( )
570
+ try_res ! ( last) . expect_non_local ( )
564
571
}
565
572
566
573
/// Convenience function to get the `DefId` of a trait by path.
0 commit comments