@@ -646,6 +646,20 @@ impl Item {
646646
647647 /// Returns a `FnHeader` if `self` is a function item, otherwise returns `None`.
648648 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+ }
649663 let header = match * self . kind {
650664 ItemKind :: ForeignFunctionItem ( _) => {
651665 let abi = tcx. fn_sig ( self . def_id . as_def_id ( ) . unwrap ( ) ) . abi ( ) ;
@@ -662,24 +676,10 @@ impl Item {
662676 }
663677 ItemKind :: FunctionItem ( _) | ItemKind :: MethodItem ( _, _) => {
664678 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) )
674680 }
675681 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 )
683683 }
684684 _ => return None ,
685685 } ;
0 commit comments