@@ -646,6 +646,20 @@ impl Item {
646
646
647
647
/// Returns a `FnHeader` if `self` is a function item, otherwise returns `None`.
648
648
crate fn fn_header ( & self , tcx : TyCtxt < ' _ > ) -> Option < hir:: FnHeader > {
649
+ fn build_fn_header (
650
+ def_id : DefId ,
651
+ tcx : TyCtxt < ' _ > ,
652
+ asyncness : hir:: IsAsync ,
653
+ ) -> hir:: FnHeader {
654
+ let sig = tcx. fn_sig ( def_id) ;
655
+ let constness =
656
+ if tcx. is_const_fn ( def_id) && is_unstable_const_fn ( tcx, def_id) . is_none ( ) {
657
+ hir:: Constness :: Const
658
+ } else {
659
+ hir:: Constness :: NotConst
660
+ } ;
661
+ hir:: FnHeader { unsafety : sig. unsafety ( ) , abi : sig. abi ( ) , constness, asyncness }
662
+ }
649
663
let header = match * self . kind {
650
664
ItemKind :: ForeignFunctionItem ( _) => {
651
665
let abi = tcx. fn_sig ( self . def_id . as_def_id ( ) . unwrap ( ) ) . abi ( ) ;
@@ -662,24 +676,10 @@ impl Item {
662
676
}
663
677
ItemKind :: FunctionItem ( _) | ItemKind :: MethodItem ( _, _) => {
664
678
let def_id = self . def_id . as_def_id ( ) . unwrap ( ) ;
665
- let sig = tcx. fn_sig ( def_id) ;
666
- let constness =
667
- if tcx. is_const_fn ( def_id) && is_unstable_const_fn ( tcx, def_id) . is_none ( ) {
668
- hir:: Constness :: Const
669
- } else {
670
- hir:: Constness :: NotConst
671
- } ;
672
- let asyncness = tcx. asyncness ( def_id) ;
673
- hir:: FnHeader { unsafety : sig. unsafety ( ) , abi : sig. abi ( ) , constness, asyncness }
679
+ build_fn_header ( def_id, tcx, tcx. asyncness ( def_id) )
674
680
}
675
681
ItemKind :: TyMethodItem ( _) => {
676
- let sig = tcx. fn_sig ( self . def_id . as_def_id ( ) . unwrap ( ) ) ;
677
- hir:: FnHeader {
678
- unsafety : sig. unsafety ( ) ,
679
- abi : sig. abi ( ) ,
680
- constness : hir:: Constness :: NotConst ,
681
- asyncness : hir:: IsAsync :: NotAsync ,
682
- }
682
+ build_fn_header ( self . def_id . as_def_id ( ) . unwrap ( ) , tcx, hir:: IsAsync :: NotAsync )
683
683
}
684
684
_ => return None ,
685
685
} ;
0 commit comments