]> git.lizzy.rs Git - rust.git/commitdiff
Update `fn_decl_by_hir_id` and `fn_sig_by_hir_id`
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Fri, 7 Feb 2020 14:34:39 +0000 (15:34 +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 c5499e7fe1793fd7027a772b6c090269f1e92717..e9d3865634883c3624d9f949198f82d8cbf42a20 100644 (file)
@@ -45,54 +45,56 @@ fn parent_node(self) -> Option<HirId> {
             _ => Some(self.parent),
         }
     }
+}
 
-    fn fn_decl(&self) -> Option<&'hir FnDecl<'hir>> {
-        match self.node {
-            Node::Item(ref item) => match item.kind {
-                ItemKind::Fn(ref sig, _, _) => Some(&sig.decl),
-                _ => None,
-            },
-
-            Node::TraitItem(ref item) => match item.kind {
-                TraitItemKind::Fn(ref sig, _) => Some(&sig.decl),
-                _ => None,
-            },
+fn fn_decl<'hir>(node: Node<'hir>) -> Option<&'hir FnDecl<'hir>> {
+    match node {
+        Node::Item(ref item) => match item.kind {
+            ItemKind::Fn(ref sig, _, _) => Some(&sig.decl),
+            _ => None,
+        },
 
-            Node::ImplItem(ref item) => match item.kind {
-                ImplItemKind::Method(ref sig, _) => Some(&sig.decl),
-                _ => None,
-            },
+        Node::TraitItem(ref item) => match item.kind {
+            TraitItemKind::Fn(ref sig, _) => Some(&sig.decl),
+            _ => None,
+        },
 
-            Node::Expr(ref expr) => match expr.kind {
-                ExprKind::Closure(_, ref fn_decl, ..) => Some(fn_decl),
-                _ => None,
-            },
+        Node::ImplItem(ref item) => match item.kind {
+            ImplItemKind::Method(ref sig, _) => Some(&sig.decl),
+            _ => None,
+        },
 
+        Node::Expr(ref expr) => match expr.kind {
+            ExprKind::Closure(_, ref fn_decl, ..) => Some(fn_decl),
             _ => None,
-        }
-    }
+        },
 
-    fn fn_sig(&self) -> Option<&'hir FnSig<'hir>> {
-        match &self.node {
-            Node::Item(item) => match &item.kind {
-                ItemKind::Fn(sig, _, _) => Some(sig),
-                _ => None,
-            },
+        _ => None,
+    }
+}
 
-            Node::TraitItem(item) => match &item.kind {
-                TraitItemKind::Fn(sig, _) => Some(sig),
-                _ => None,
-            },
+fn fn_sig<'hir>(node: Node<'hir>) -> Option<&'hir FnSig<'hir>> {
+    match &node {
+        Node::Item(item) => match &item.kind {
+            ItemKind::Fn(sig, _, _) => Some(sig),
+            _ => None,
+        },
 
-            Node::ImplItem(item) => match &item.kind {
-                ImplItemKind::Method(sig, _) => Some(sig),
-                _ => None,
-            },
+        Node::TraitItem(item) => match &item.kind {
+            TraitItemKind::Fn(sig, _) => Some(sig),
+            _ => None,
+        },
 
+        Node::ImplItem(item) => match &item.kind {
+            ImplItemKind::Method(sig, _) => Some(sig),
             _ => None,
-        }
+        },
+
+        _ => None,
     }
+}
 
+impl<'hir> Entry<'hir> {
     fn associated_body(self) -> Option<BodyId> {
         match self.node {
             Node::Item(item) => match item.kind {
@@ -433,18 +435,18 @@ pub fn body(&self, id: BodyId) -> &'hir Body<'hir> {
     }
 
     pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
-        if let Some(entry) = self.find_entry(hir_id) {
-            entry.fn_decl()
+        if let Some(node) = self.find(hir_id) {
+            fn_decl(node)
         } else {
-            bug!("no entry for hir_id `{}`", hir_id)
+            bug!("no node for hir_id `{}`", hir_id)
         }
     }
 
     pub fn fn_sig_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
-        if let Some(entry) = self.find_entry(hir_id) {
-            entry.fn_sig()
+        if let Some(node) = self.find(hir_id) {
+            fn_sig(node)
         } else {
-            bug!("no entry for hir_id `{}`", hir_id)
+            bug!("no node for hir_id `{}`", hir_id)
         }
     }