match self.node {
Node::Item(ref item) => {
match item.kind {
- ItemKind::Fn(ref fn_decl, _, _, _) => Some(fn_decl),
+ ItemKind::Fn(ref sig, _, _) => Some(&sig.decl),
_ => None,
}
}
Node::TraitItem(ref item) => {
match item.kind {
- TraitItemKind::Method(ref method_sig, _) => Some(&method_sig.decl),
+ TraitItemKind::Method(ref sig, _) => Some(&sig.decl),
_ => None
}
}
Node::ImplItem(ref item) => {
match item.kind {
- ImplItemKind::Method(ref method_sig, _) => Some(&method_sig.decl),
+ ImplItemKind::Method(ref sig, _) => Some(&sig.decl),
_ => None,
}
}
}
}
+ 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) => {
match item.kind {
ItemKind::Const(_, body) |
ItemKind::Static(.., body) |
- ItemKind::Fn(_, _, _, body) => Some(body),
+ ItemKind::Fn(.., body) => Some(body),
_ => None,
}
}
}
}
+ 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`.
Node::TraitItem(ref trait_item) => Some(&trait_item.generics),
Node::Item(ref item) => {
match item.kind {
- ItemKind::Fn(_, _, ref generics, _) |
+ ItemKind::Fn(_, ref generics, _) |
ItemKind::TyAlias(_, ref generics) |
ItemKind::Enum(_, ref generics) |
ItemKind::Struct(_, ref generics) |
..
}) => true,
Node::Item(&Item {
- kind: ItemKind::Fn(_, header, ..),
+ kind: ItemKind::Fn(ref sig, ..),
..
- }) => header.constness == Constness::Const,
+ }) => sig.header.constness == Constness::Const,
_ => false,
}
}