about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/hir
diff options
context:
space:
mode:
authorMiguel Guarniz <mi9uel9@gmail.com>2022-07-15 23:13:04 -0400
committerMiguel Guarniz <mi9uel9@gmail.com>2022-07-29 18:25:58 -0400
commit25bdc8965e7a80cb3a72da79ca568953738fe433 (patch)
tree9e5c141b84918483db882f87c8d1bbb6b3702da1 /compiler/rustc_middle/src/hir
parent3924dac7bb29bc8eb348059c901e8f912399c857 (diff)
downloadrust-25bdc8965e7a80cb3a72da79ca568953738fe433.tar.gz
rust-25bdc8965e7a80cb3a72da79ca568953738fe433.zip
Change maybe_body_owned_by to take local def id
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Diffstat (limited to 'compiler/rustc_middle/src/hir')
-rw-r--r--compiler/rustc_middle/src/hir/map/mod.rs15
-rw-r--r--compiler/rustc_middle/src/hir/mod.rs5
2 files changed, 11 insertions, 9 deletions
diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs
index 0001e1aa53e..adb591fe09c 100644
--- a/compiler/rustc_middle/src/hir/map/mod.rs
+++ b/compiler/rustc_middle/src/hir/map/mod.rs
@@ -398,7 +398,7 @@ impl<'hir> Map<'hir> {
 
     pub fn enclosing_body_owner(self, hir_id: HirId) -> HirId {
         for (parent, _) in self.parent_iter(hir_id) {
-            if let Some(body) = self.maybe_body_owned_by(parent) {
+            if let Some(local_did) = parent.as_owner() && let Some(body) = self.maybe_body_owned_by(local_did) {
                 return self.body_owner(body);
             }
         }
@@ -419,19 +419,20 @@ impl<'hir> Map<'hir> {
         self.local_def_id(self.body_owner(id))
     }
 
-    /// Given a `HirId`, returns the `BodyId` associated with it,
+    /// Given a `LocalDefId`, returns the `BodyId` associated with it,
     /// if the node is a body owner, otherwise returns `None`.
-    pub fn maybe_body_owned_by(self, hir_id: HirId) -> Option<BodyId> {
-        self.find(hir_id).map(associated_body).flatten()
+    pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId> {
+        self.get_if_local(id.to_def_id()).map(associated_body).flatten()
     }
 
     /// Given a body owner's id, returns the `BodyId` associated with it.
-    pub fn body_owned_by(self, id: HirId) -> BodyId {
+    pub fn body_owned_by(self, id: LocalDefId) -> BodyId {
         self.maybe_body_owned_by(id).unwrap_or_else(|| {
+            let hir_id = self.local_def_id_to_hir_id(id);
             span_bug!(
-                self.span(id),
+                self.span(hir_id),
                 "body_owned_by: {} has no associated body",
-                self.node_to_string(id)
+                self.node_to_string(hir_id)
             );
         })
     }
diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs
index a605e234be9..3c008749358 100644
--- a/compiler/rustc_middle/src/hir/mod.rs
+++ b/compiler/rustc_middle/src/hir/mod.rs
@@ -157,8 +157,9 @@ pub fn provide(providers: &mut Providers) {
     };
     providers.fn_arg_names = |tcx, id| {
         let hir = tcx.hir();
-        let hir_id = hir.local_def_id_to_hir_id(id.expect_local());
-        if let Some(body_id) = hir.maybe_body_owned_by(hir_id) {
+        let local_did = id.expect_local();
+        let hir_id = hir.local_def_id_to_hir_id(local_did);
+        if let Some(body_id) = hir.maybe_body_owned_by(local_did) {
             tcx.arena.alloc_from_iter(hir.body_param_names(body_id))
         } else if let Node::TraitItem(&TraitItem {
             kind: TraitItemKind::Fn(_, TraitFn::Required(idents)),