@@ -170,6 +170,40 @@ impl<'hir> MapEntry<'hir> {
170
170
} )
171
171
}
172
172
173
+ fn fn_decl ( & self ) -> Option < & FnDecl > {
174
+ match self {
175
+ EntryItem ( _, _, ref item) => {
176
+ match item. node {
177
+ ItemFn ( ref fn_decl, _, _, _, _, _) => Some ( & fn_decl) ,
178
+ _ => None ,
179
+ }
180
+ }
181
+
182
+ EntryTraitItem ( _, _, ref item) => {
183
+ match item. node {
184
+ TraitItemKind :: Method ( ref method_sig, _) => Some ( & method_sig. decl ) ,
185
+ _ => None
186
+ }
187
+ }
188
+
189
+ EntryImplItem ( _, _, ref item) => {
190
+ match item. node {
191
+ ImplItemKind :: Method ( ref method_sig, _) => Some ( & method_sig. decl ) ,
192
+ _ => None ,
193
+ }
194
+ }
195
+
196
+ EntryExpr ( _, _, ref expr) => {
197
+ match expr. node {
198
+ ExprClosure ( _, ref fn_decl, ..) => Some ( & fn_decl) ,
199
+ _ => None ,
200
+ }
201
+ }
202
+
203
+ _ => None
204
+ }
205
+ }
206
+
173
207
fn associated_body ( self ) -> Option < BodyId > {
174
208
match self {
175
209
EntryItem ( _, _, item) => {
@@ -502,6 +536,14 @@ impl<'hir> Map<'hir> {
502
536
self . forest . krate . body ( id)
503
537
}
504
538
539
+ pub fn fn_decl ( & self , node_id : ast:: NodeId ) -> Option < FnDecl > {
540
+ if let Some ( entry) = self . find_entry ( node_id) {
541
+ entry. fn_decl ( ) . map ( |fd| fd. clone ( ) )
542
+ } else {
543
+ bug ! ( "no entry for node_id `{}`" , node_id)
544
+ }
545
+ }
546
+
505
547
/// Returns the `NodeId` that corresponds to the definition of
506
548
/// which this is the body of, i.e. a `fn`, `const` or `static`
507
549
/// item (possibly associated), a closure, or a `hir::AnonConst`.
0 commit comments