@@ -1488,24 +1488,25 @@ fn first_not_private(
1488
1488
hir_id : hir:: HirId ,
1489
1489
path : & hir:: Path < ' _ > ,
1490
1490
) -> Option < Path > {
1491
- if path. segments . is_empty ( ) {
1492
- return None ;
1493
- }
1494
- let parent_def_id = if path. segments . len ( ) == 1 {
1495
- // Then it's available in the same scope as the owner.
1496
- hir_id. owner . def_id
1497
- } else {
1498
- // It's not available in the same scope, so we start from the parent of the item.
1499
- path. segments [ path. segments . len ( ) - 2 ] . res . opt_def_id ( ) ?. as_local ( ) ?
1491
+ let ( parent_def_id, mut ident) = match & path. segments [ ..] {
1492
+ [ ] => return None ,
1493
+ // Relative paths are available in the same scope as the owner.
1494
+ [ leaf] => ( cx. tcx . local_parent ( hir_id. owner . def_id ) , leaf. ident ) ,
1495
+ // So are self paths.
1496
+ [ parent, leaf] if parent. ident . name == kw:: SelfLower => {
1497
+ ( cx. tcx . local_parent ( hir_id. owner . def_id ) , leaf. ident )
1498
+ }
1499
+ // Crate paths are not. We start from the crate root.
1500
+ [ parent, leaf] if parent. ident . name == kw:: Crate => {
1501
+ ( LOCAL_CRATE . as_def_id ( ) . as_local ( ) ?, leaf. ident )
1502
+ }
1503
+ // Absolute paths are not. We start from the parent of the item.
1504
+ [ .., parent, leaf] => ( parent. res . opt_def_id ( ) ?. as_local ( ) ?, leaf. ident ) ,
1500
1505
} ;
1501
1506
let target_def_id = path. res . opt_def_id ( ) ?;
1502
- let mut ident = path. segments . last ( ) . unwrap ( ) . ident ;
1503
1507
// First we try to get the `DefId` of the item.
1504
- for child in cx
1505
- . tcx
1506
- . module_children_local ( cx. tcx . local_parent ( parent_def_id) )
1507
- . iter ( )
1508
- . filter ( move |c| c. ident == ident)
1508
+ for child in
1509
+ cx. tcx . module_children_local ( parent_def_id) . iter ( ) . filter ( move |c| c. ident == ident)
1509
1510
{
1510
1511
if let Res :: Def ( DefKind :: Ctor ( ..) , _) | Res :: SelfCtor ( ..) = child. res {
1511
1512
continue ;
@@ -1518,26 +1519,20 @@ fn first_not_private(
1518
1519
let Some ( local_use_def_id) = use_def_id. as_local ( )
1519
1520
{
1520
1521
let hir = cx. tcx . hir ( ) ;
1521
- // let parent_mod = hir.local_def_id_to_hir_id();
1522
1522
for item_id in hir. module_items ( cx. tcx . local_parent ( local_use_def_id) ) {
1523
1523
let item = hir. item ( item_id) ;
1524
- if item. ident == ident {
1525
- match item. kind {
1526
- hir:: ItemKind :: Use ( path, _) => {
1527
- for res in & path. res {
1528
- if let Res :: Def ( DefKind :: Ctor ( ..) , _) | Res :: SelfCtor ( ..) = res {
1529
- continue ;
1530
- }
1531
- if !cx. tcx . is_doc_hidden ( use_def_id) &&
1532
- cx. tcx . local_visibility ( local_use_def_id) . is_public ( ) {
1533
- break ' reexps;
1534
- }
1535
- ident = path. segments . last ( ) . unwrap ( ) . ident ;
1536
- last_path_res = Some ( ( path, res) ) ;
1537
- continue ' reexps;
1538
- }
1524
+ if item. ident == ident && let hir:: ItemKind :: Use ( path, _) = item. kind {
1525
+ for res in & path. res {
1526
+ if let Res :: Def ( DefKind :: Ctor ( ..) , _) | Res :: SelfCtor ( ..) = res {
1527
+ continue ;
1528
+ }
1529
+ if !cx. tcx . is_doc_hidden ( use_def_id) &&
1530
+ cx. tcx . local_visibility ( local_use_def_id) . is_public ( ) {
1531
+ break ' reexps;
1539
1532
}
1540
- _ => { }
1533
+ ident = path. segments . last ( ) . unwrap ( ) . ident ;
1534
+ last_path_res = Some ( ( path, res) ) ;
1535
+ continue ' reexps;
1541
1536
}
1542
1537
}
1543
1538
}
0 commit comments