]> git.lizzy.rs Git - rust.git/commitdiff
Update `body_owner` and `maybe_body_owned_by`
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Fri, 7 Feb 2020 15:10:50 +0000 (16:10 +0100)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Sat, 14 Mar 2020 21:52:28 +0000 (22:52 +0100)
src/librustc/hir/map/mod.rs

index e9d3865634883c3624d9f949198f82d8cbf42a20..38260eac890b8fcd315151a194a74f5d9dfe24f6 100644 (file)
@@ -94,43 +94,41 @@ fn fn_sig<'hir>(node: Node<'hir>) -> Option<&'hir FnSig<'hir>> {
     }
 }
 
-impl<'hir> Entry<'hir> {
-    fn associated_body(self) -> Option<BodyId> {
-        match self.node {
-            Node::Item(item) => match item.kind {
-                ItemKind::Const(_, body) | ItemKind::Static(.., body) | ItemKind::Fn(.., body) => {
-                    Some(body)
-                }
-                _ => None,
-            },
-
-            Node::TraitItem(item) => match item.kind {
-                TraitItemKind::Const(_, Some(body))
-                | TraitItemKind::Fn(_, TraitMethod::Provided(body)) => Some(body),
-                _ => None,
-            },
+fn associated_body<'hir>(node: Node<'hir>) -> Option<BodyId> {
+    match node {
+        Node::Item(item) => match item.kind {
+            ItemKind::Const(_, body) | ItemKind::Static(.., body) | ItemKind::Fn(.., body) => {
+                Some(body)
+            }
+            _ => None,
+        },
 
-            Node::ImplItem(item) => match item.kind {
-                ImplItemKind::Const(_, body) | ImplItemKind::Method(_, body) => Some(body),
-                _ => None,
-            },
+        Node::TraitItem(item) => match item.kind {
+            TraitItemKind::Const(_, Some(body))
+            | TraitItemKind::Fn(_, TraitMethod::Provided(body)) => Some(body),
+            _ => None,
+        },
 
-            Node::AnonConst(constant) => Some(constant.body),
+        Node::ImplItem(item) => match item.kind {
+            ImplItemKind::Const(_, body) | ImplItemKind::Method(_, body) => Some(body),
+            _ => None,
+        },
 
-            Node::Expr(expr) => match expr.kind {
-                ExprKind::Closure(.., body, _, _) => Some(body),
-                _ => None,
-            },
+        Node::AnonConst(constant) => Some(constant.body),
 
+        Node::Expr(expr) => match expr.kind {
+            ExprKind::Closure(.., body, _, _) => Some(body),
             _ => None,
-        }
+        },
+
+        _ => None,
     }
+}
 
-    fn is_body_owner(self, hir_id: HirId) -> bool {
-        match self.associated_body() {
-            Some(b) => b.hir_id == hir_id,
-            None => false,
-        }
+fn is_body_owner<'hir>(node: Node<'hir>, hir_id: HirId) -> bool {
+    match associated_body(node) {
+        Some(b) => b.hir_id == hir_id,
+        None => false,
     }
 }
 
@@ -455,7 +453,7 @@ pub fn fn_sig_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
     /// item (possibly associated), a closure, or a `hir::AnonConst`.
     pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId {
         let parent = self.get_parent_node(hir_id);
-        assert!(self.lookup(parent).map_or(false, |e| e.is_body_owner(hir_id)));
+        assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)));
         parent
     }
 
@@ -466,14 +464,8 @@ pub fn body_owner_def_id(&self, id: BodyId) -> DefId {
     /// Given a `HirId`, 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> {
-        if let Some(entry) = self.find_entry(hir_id) {
-            if self.dep_graph.is_fully_enabled() {
-                let hir_id_owner = hir_id.owner;
-                let def_path_hash = self.definitions.def_path_hash(hir_id_owner);
-                self.dep_graph.read(def_path_hash.to_dep_node(DepKind::HirBody));
-            }
-
-            entry.associated_body()
+        if let Some(node) = self.find(hir_id) {
+            associated_body(node)
         } else {
             bug!("no entry for id `{}`", hir_id)
         }