@@ -398,7 +398,7 @@ impl<'hir> Map<'hir> {
398398
399399 pub fn enclosing_body_owner(self, hir_id: HirId) -> HirId {
400400 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 ) {
402402 return self.body_owner(body);
403403 }
404404 }
@@ -419,19 +419,20 @@ impl<'hir> Map<'hir> {
419419 self.local_def_id(self.body_owner(id))
420420 }
421421
422- /// Given a `HirId `, returns the `BodyId` associated with it,
422+ /// Given a `LocalDefId `, returns the `BodyId` associated with it,
423423 /// 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()
426426 }
427427
428428 /// 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 {
430430 self.maybe_body_owned_by(id).unwrap_or_else(|| {
431+ let hir_id = self.local_def_id_to_hir_id(id);
431432 span_bug!(
432- self.span(id ),
433+ self.span(hir_id ),
433434 "body_owned_by: {} has no associated body",
434- self.node_to_string(id )
435+ self.node_to_string(hir_id )
435436 );
436437 })
437438 }
0 commit comments