Skip to content

Commit 33b62be

Browse files
Get FnSig by HirId
1 parent 8b7d2bc commit 33b62be

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/librustc/hir/map/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,33 @@ impl<'hir> Entry<'hir> {
7979
}
8080
}
8181

82+
fn fn_sig(&self) -> Option<&'hir FnSig> {
83+
match &self.node {
84+
Node::Item(item) => {
85+
match &item.kind {
86+
ItemKind::Fn(sig, _, _) => Some(sig),
87+
_ => None,
88+
}
89+
}
90+
91+
Node::TraitItem(item) => {
92+
match &item.kind {
93+
TraitItemKind::Method(sig, _) => Some(sig),
94+
_ => None
95+
}
96+
}
97+
98+
Node::ImplItem(item) => {
99+
match &item.kind {
100+
ImplItemKind::Method(sig, _) => Some(sig),
101+
_ => None,
102+
}
103+
}
104+
105+
_ => None,
106+
}
107+
}
108+
82109
fn associated_body(self) -> Option<BodyId> {
83110
match self.node {
84111
Node::Item(item) => {
@@ -450,6 +477,14 @@ impl<'hir> Map<'hir> {
450477
}
451478
}
452479

480+
pub fn fn_sig_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnSig> {
481+
if let Some(entry) = self.find_entry(hir_id) {
482+
entry.fn_sig()
483+
} else {
484+
bug!("no entry for hir_id `{}`", hir_id)
485+
}
486+
}
487+
453488
/// Returns the `HirId` that corresponds to the definition of
454489
/// which this is the body of, i.e., a `fn`, `const` or `static`
455490
/// item (possibly associated), a closure, or a `hir::AnonConst`.

0 commit comments

Comments
 (0)