mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Get FnSig
by HirId
This commit is contained in:
parent
8b7d2bc270
commit
33b62be862
@ -79,6 +79,33 @@ impl<'hir> Entry<'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
fn fn_sig(&self) -> Option<&'hir FnSig> {
|
||||
match &self.node {
|
||||
Node::Item(item) => {
|
||||
match &item.kind {
|
||||
ItemKind::Fn(sig, _, _) => Some(sig),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
Node::TraitItem(item) => {
|
||||
match &item.kind {
|
||||
TraitItemKind::Method(sig, _) => Some(sig),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
Node::ImplItem(item) => {
|
||||
match &item.kind {
|
||||
ImplItemKind::Method(sig, _) => Some(sig),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn associated_body(self) -> Option<BodyId> {
|
||||
match self.node {
|
||||
Node::Item(item) => {
|
||||
@ -450,6 +477,14 @@ impl<'hir> Map<'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fn_sig_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnSig> {
|
||||
if let Some(entry) = self.find_entry(hir_id) {
|
||||
entry.fn_sig()
|
||||
} else {
|
||||
bug!("no entry for hir_id `{}`", hir_id)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the `HirId` that corresponds to the definition of
|
||||
/// which this is the body of, i.e., a `fn`, `const` or `static`
|
||||
/// item (possibly associated), a closure, or a `hir::AnonConst`.
|
||||
|
Loading…
Reference in New Issue
Block a user