@@ -337,23 +337,28 @@ impl<'hir> Map<'hir> {
337
337
}
338
338
339
339
fn find_entry ( & self , id : HirId ) -> Option < Entry < ' hir > > {
340
- Some ( self . get_entry ( id) )
341
- }
342
-
343
- fn get_entry ( & self , id : HirId ) -> Entry < ' hir > {
344
340
if id. local_id == ItemLocalId :: from_u32 ( 0 ) {
345
341
let owner = self . tcx . hir_owner ( id. owner ) ;
346
- Entry { parent : owner. parent , node : owner. node }
342
+ owner . map ( |owner| Entry { parent : owner. parent , node : owner. node } )
347
343
} else {
348
344
let owner = self . tcx . hir_owner_nodes ( id. owner ) ;
349
- let node = owner. nodes [ id. local_id ] . as_ref ( ) . unwrap ( ) ;
350
- // FIXME(eddyb) use a single generic type insted of having both
351
- // `Entry` and `ParentedNode`, which are effectively the same.
352
- // Alternatively, rewrite code using `Entry` to use `ParentedNode`.
353
- Entry { parent : HirId { owner : id. owner , local_id : node. parent } , node : node. node }
345
+ owner. and_then ( |owner| {
346
+ let node = owner. nodes [ id. local_id ] . as_ref ( ) ;
347
+ // FIXME(eddyb) use a single generic type insted of having both
348
+ // `Entry` and `ParentedNode`, which are effectively the same.
349
+ // Alternatively, rewrite code using `Entry` to use `ParentedNode`.
350
+ node. map ( |node| Entry {
351
+ parent : HirId { owner : id. owner , local_id : node. parent } ,
352
+ node : node. node ,
353
+ } )
354
+ } )
354
355
}
355
356
}
356
357
358
+ fn get_entry ( & self , id : HirId ) -> Entry < ' hir > {
359
+ self . find_entry ( id) . unwrap ( )
360
+ }
361
+
357
362
pub fn item ( & self , id : HirId ) -> & ' hir Item < ' hir > {
358
363
match self . find ( id) . unwrap ( ) {
359
364
Node :: Item ( item) => item,
@@ -376,7 +381,7 @@ impl<'hir> Map<'hir> {
376
381
}
377
382
378
383
pub fn body ( & self , id : BodyId ) -> & ' hir Body < ' hir > {
379
- self . tcx . hir_owner_nodes ( id. hir_id . owner ) . bodies . get ( & id. hir_id . local_id ) . unwrap ( )
384
+ self . tcx . hir_owner_nodes ( id. hir_id . owner ) . unwrap ( ) . bodies . get ( & id. hir_id . local_id ) . unwrap ( )
380
385
}
381
386
382
387
pub fn fn_decl_by_hir_id ( & self , hir_id : HirId ) -> Option < & ' hir FnDecl < ' hir > > {
@@ -536,8 +541,9 @@ impl<'hir> Map<'hir> {
536
541
537
542
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
538
543
pub fn find ( & self , hir_id : HirId ) -> Option < Node < ' hir > > {
539
- let node = self . get_entry ( hir_id) . node ;
540
- if let Node :: Crate ( ..) = node { None } else { Some ( node) }
544
+ self . find_entry ( hir_id) . and_then ( |entry| {
545
+ if let Node :: Crate ( ..) = entry. node { None } else { Some ( entry. node ) }
546
+ } )
541
547
}
542
548
543
549
/// Similar to `get_parent`; returns the parent HIR Id, or just `hir_id` if there
0 commit comments