Skip to content

Commit d3c7394

Browse files
committed
Update fn_decl_by_hir_id and fn_sig_by_hir_id
1 parent e1a9626 commit d3c7394

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

src/librustc/hir/map/mod.rs

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,54 +45,56 @@ impl<'hir> Entry<'hir> {
4545
_ => Some(self.parent),
4646
}
4747
}
48+
}
4849

49-
fn fn_decl(&self) -> Option<&'hir FnDecl<'hir>> {
50-
match self.node {
51-
Node::Item(ref item) => match item.kind {
52-
ItemKind::Fn(ref sig, _, _) => Some(&sig.decl),
53-
_ => None,
54-
},
55-
56-
Node::TraitItem(ref item) => match item.kind {
57-
TraitItemKind::Fn(ref sig, _) => Some(&sig.decl),
58-
_ => None,
59-
},
50+
fn fn_decl<'hir>(node: Node<'hir>) -> Option<&'hir FnDecl<'hir>> {
51+
match node {
52+
Node::Item(ref item) => match item.kind {
53+
ItemKind::Fn(ref sig, _, _) => Some(&sig.decl),
54+
_ => None,
55+
},
6056

61-
Node::ImplItem(ref item) => match item.kind {
62-
ImplItemKind::Method(ref sig, _) => Some(&sig.decl),
63-
_ => None,
64-
},
57+
Node::TraitItem(ref item) => match item.kind {
58+
TraitItemKind::Fn(ref sig, _) => Some(&sig.decl),
59+
_ => None,
60+
},
6561

66-
Node::Expr(ref expr) => match expr.kind {
67-
ExprKind::Closure(_, ref fn_decl, ..) => Some(fn_decl),
68-
_ => None,
69-
},
62+
Node::ImplItem(ref item) => match item.kind {
63+
ImplItemKind::Method(ref sig, _) => Some(&sig.decl),
64+
_ => None,
65+
},
7066

67+
Node::Expr(ref expr) => match expr.kind {
68+
ExprKind::Closure(_, ref fn_decl, ..) => Some(fn_decl),
7169
_ => None,
72-
}
73-
}
70+
},
7471

75-
fn fn_sig(&self) -> Option<&'hir FnSig<'hir>> {
76-
match &self.node {
77-
Node::Item(item) => match &item.kind {
78-
ItemKind::Fn(sig, _, _) => Some(sig),
79-
_ => None,
80-
},
72+
_ => None,
73+
}
74+
}
8175

82-
Node::TraitItem(item) => match &item.kind {
83-
TraitItemKind::Fn(sig, _) => Some(sig),
84-
_ => None,
85-
},
76+
fn fn_sig<'hir>(node: Node<'hir>) -> Option<&'hir FnSig<'hir>> {
77+
match &node {
78+
Node::Item(item) => match &item.kind {
79+
ItemKind::Fn(sig, _, _) => Some(sig),
80+
_ => None,
81+
},
8682

87-
Node::ImplItem(item) => match &item.kind {
88-
ImplItemKind::Method(sig, _) => Some(sig),
89-
_ => None,
90-
},
83+
Node::TraitItem(item) => match &item.kind {
84+
TraitItemKind::Fn(sig, _) => Some(sig),
85+
_ => None,
86+
},
9187

88+
Node::ImplItem(item) => match &item.kind {
89+
ImplItemKind::Method(sig, _) => Some(sig),
9290
_ => None,
93-
}
91+
},
92+
93+
_ => None,
9494
}
95+
}
9596

97+
impl<'hir> Entry<'hir> {
9698
fn associated_body(self) -> Option<BodyId> {
9799
match self.node {
98100
Node::Item(item) => match item.kind {
@@ -433,18 +435,18 @@ impl<'hir> Map<'hir> {
433435
}
434436

435437
pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
436-
if let Some(entry) = self.find_entry(hir_id) {
437-
entry.fn_decl()
438+
if let Some(node) = self.find(hir_id) {
439+
fn_decl(node)
438440
} else {
439-
bug!("no entry for hir_id `{}`", hir_id)
441+
bug!("no node for hir_id `{}`", hir_id)
440442
}
441443
}
442444

443445
pub fn fn_sig_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
444-
if let Some(entry) = self.find_entry(hir_id) {
445-
entry.fn_sig()
446+
if let Some(node) = self.find(hir_id) {
447+
fn_sig(node)
446448
} else {
447-
bug!("no entry for hir_id `{}`", hir_id)
449+
bug!("no node for hir_id `{}`", hir_id)
448450
}
449451
}
450452

0 commit comments

Comments
 (0)