@@ -1505,24 +1505,25 @@ fn first_not_private(
1505
1505
hir_id : hir:: HirId ,
1506
1506
path : & hir:: Path < ' _ > ,
1507
1507
) -> Option < Path > {
1508
- if path. segments . is_empty ( ) {
1509
- return None ;
1510
- }
1511
- let parent_def_id = if path. segments . len ( ) == 1 {
1512
- // Then it's available in the same scope as the owner.
1513
- hir_id. owner . def_id
1514
- } else {
1515
- // It's not available in the same scope, so we start from the parent of the item.
1516
- path. segments [ path. segments . len ( ) - 2 ] . res . opt_def_id ( ) ?. as_local ( ) ?
1508
+ let ( parent_def_id, mut ident) = match & path. segments [ ..] {
1509
+ [ ] => return None ,
1510
+ // Relative paths are available in the same scope as the owner.
1511
+ [ leaf] => ( cx. tcx . local_parent ( hir_id. owner . def_id ) , leaf. ident ) ,
1512
+ // So are self paths.
1513
+ [ parent, leaf] if parent. ident . name == kw:: SelfLower => {
1514
+ ( cx. tcx . local_parent ( hir_id. owner . def_id ) , leaf. ident )
1515
+ }
1516
+ // Crate paths are not. We start from the crate root.
1517
+ [ parent, leaf] if parent. ident . name == kw:: Crate => {
1518
+ ( LOCAL_CRATE . as_def_id ( ) . as_local ( ) ?, leaf. ident )
1519
+ }
1520
+ // Absolute paths are not. We start from the parent of the item.
1521
+ [ .., parent, leaf] => ( parent. res . opt_def_id ( ) ?. as_local ( ) ?, leaf. ident ) ,
1517
1522
} ;
1518
1523
let target_def_id = path. res . opt_def_id ( ) ?;
1519
- let mut ident = path. segments . last ( ) . unwrap ( ) . ident ;
1520
1524
// First we try to get the `DefId` of the item.
1521
- for child in cx
1522
- . tcx
1523
- . module_children_local ( cx. tcx . local_parent ( parent_def_id) )
1524
- . iter ( )
1525
- . filter ( move |c| c. ident == ident)
1525
+ for child in
1526
+ cx. tcx . module_children_local ( parent_def_id) . iter ( ) . filter ( move |c| c. ident == ident)
1526
1527
{
1527
1528
if let Res :: Def ( DefKind :: Ctor ( ..) , _) | Res :: SelfCtor ( ..) = child. res {
1528
1529
continue ;
@@ -1535,26 +1536,20 @@ fn first_not_private(
1535
1536
let Some ( local_use_def_id) = use_def_id. as_local ( )
1536
1537
{
1537
1538
let hir = cx. tcx . hir ( ) ;
1538
- // let parent_mod = hir.local_def_id_to_hir_id();
1539
1539
for item_id in hir. module_items ( cx. tcx . local_parent ( local_use_def_id) ) {
1540
1540
let item = hir. item ( item_id) ;
1541
- if item. ident == ident {
1542
- match item. kind {
1543
- hir:: ItemKind :: Use ( path, _) => {
1544
- for res in & path. res {
1545
- if let Res :: Def ( DefKind :: Ctor ( ..) , _) | Res :: SelfCtor ( ..) = res {
1546
- continue ;
1547
- }
1548
- if !cx. tcx . is_doc_hidden ( use_def_id) &&
1549
- cx. tcx . local_visibility ( local_use_def_id) . is_public ( ) {
1550
- break ' reexps;
1551
- }
1552
- ident = path. segments . last ( ) . unwrap ( ) . ident ;
1553
- last_path_res = Some ( ( path, res) ) ;
1554
- continue ' reexps;
1555
- }
1541
+ if item. ident == ident && let hir:: ItemKind :: Use ( path, _) = item. kind {
1542
+ for res in & path. res {
1543
+ if let Res :: Def ( DefKind :: Ctor ( ..) , _) | Res :: SelfCtor ( ..) = res {
1544
+ continue ;
1545
+ }
1546
+ if !cx. tcx . is_doc_hidden ( use_def_id) &&
1547
+ cx. tcx . local_visibility ( local_use_def_id) . is_public ( ) {
1548
+ break ' reexps;
1556
1549
}
1557
- _ => { }
1550
+ ident = path. segments . last ( ) . unwrap ( ) . ident ;
1551
+ last_path_res = Some ( ( path, res) ) ;
1552
+ continue ' reexps;
1558
1553
}
1559
1554
}
1560
1555
}
0 commit comments