@@ -396,10 +396,10 @@ impl<'hir> Map<'hir> {
396
396
}
397
397
}
398
398
399
- pub fn enclosing_body_owner ( self , hir_id : HirId ) -> HirId {
399
+ pub fn enclosing_body_owner ( self , hir_id : HirId ) -> LocalDefId {
400
400
for ( parent, _) in self . parent_iter ( hir_id) {
401
- if let Some ( body) = self . maybe_body_owned_by ( parent) {
402
- return self . body_owner ( body) ;
401
+ if let Some ( body) = self . find ( parent) . map ( associated_body ) . flatten ( ) {
402
+ return self . body_owner_def_id ( body) ;
403
403
}
404
404
}
405
405
@@ -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
}
@@ -670,7 +671,7 @@ impl<'hir> Map<'hir> {
670
671
/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
671
672
/// Used exclusively for diagnostics, to avoid suggestion function calls.
672
673
pub fn is_inside_const_context ( self , hir_id : HirId ) -> bool {
673
- self . body_const_context ( self . local_def_id ( self . enclosing_body_owner ( hir_id) ) ) . is_some ( )
674
+ self . body_const_context ( self . enclosing_body_owner ( hir_id) ) . is_some ( )
674
675
}
675
676
676
677
/// Retrieves the `HirId` for `id`'s enclosing method, unless there's a
0 commit comments