@@ -398,7 +398,7 @@ impl<'hir> Map<'hir> {
398
398
399
399
pub fn enclosing_body_owner ( self , hir_id : HirId ) -> HirId {
400
400
for ( parent, _) in self . parent_iter ( hir_id) {
401
- if let Some ( body) = self . maybe_body_owned_by ( parent ) {
401
+ if let Some ( local_did ) = parent . as_owner ( ) && let Some ( body) = self . maybe_body_owned_by ( local_did ) {
402
402
return self . body_owner ( body) ;
403
403
}
404
404
}
@@ -419,19 +419,20 @@ impl<'hir> Map<'hir> {
419
419
self . local_def_id ( self . body_owner ( id) )
420
420
}
421
421
422
- /// Given a `HirId `, returns the `BodyId` associated with it,
422
+ /// Given a `LocalDefId `, returns the `BodyId` associated with it,
423
423
/// if the node is a body owner, otherwise returns `None`.
424
- pub fn maybe_body_owned_by ( self , hir_id : HirId ) -> Option < BodyId > {
425
- self . find ( hir_id ) . map ( associated_body) . flatten ( )
424
+ pub fn maybe_body_owned_by ( self , id : LocalDefId ) -> Option < BodyId > {
425
+ self . get_if_local ( id . to_def_id ( ) ) . map ( associated_body) . flatten ( )
426
426
}
427
427
428
428
/// Given a body owner's id, returns the `BodyId` associated with it.
429
- pub fn body_owned_by ( self , id : HirId ) -> BodyId {
429
+ pub fn body_owned_by ( self , id : LocalDefId ) -> BodyId {
430
430
self . maybe_body_owned_by ( id) . unwrap_or_else ( || {
431
+ let hir_id = self . local_def_id_to_hir_id ( id) ;
431
432
span_bug ! (
432
- self . span( id ) ,
433
+ self . span( hir_id ) ,
433
434
"body_owned_by: {} has no associated body" ,
434
- self . node_to_string( id )
435
+ self . node_to_string( hir_id )
435
436
) ;
436
437
} )
437
438
}
0 commit comments