@@ -543,38 +543,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
543543 & indices,
544544 ) ;
545545
546- let ( unnormalized_output_ty, mut unnormalized_input_tys) =
546+ let ( unnormalized_output_ty, unnormalized_input_tys) =
547547 inputs_and_output. split_last ( ) . unwrap ( ) ;
548548
549- // C-variadic fns also have a `VaList` input that's not listed in the signature
550- // (as it's created inside the body itself, not passed in from outside).
551- if let DefiningTy :: FnDef ( def_id, _) = defining_ty {
552- if self . infcx . tcx . fn_sig ( def_id) . skip_binder ( ) . c_variadic ( ) {
553- let va_list_did = self
554- . infcx
555- . tcx
556- . require_lang_item ( LangItem :: VaList , self . infcx . tcx . def_span ( self . mir_def ) ) ;
557-
558- let reg_vid = self
559- . infcx
560- . next_nll_region_var ( NllRegionVariableOrigin :: FreeRegion , || {
561- RegionCtxt :: Free ( sym:: c_dash_variadic)
562- } )
563- . as_var ( ) ;
564-
565- let region = ty:: Region :: new_var ( self . infcx . tcx , reg_vid) ;
566- let va_list_ty = self
567- . infcx
568- . tcx
569- . type_of ( va_list_did)
570- . instantiate ( self . infcx . tcx , & [ region. into ( ) ] ) ;
571-
572- unnormalized_input_tys = self . infcx . tcx . mk_type_list_from_iter (
573- unnormalized_input_tys. iter ( ) . copied ( ) . chain ( iter:: once ( va_list_ty) ) ,
574- ) ;
575- }
576- }
577-
578549 let fr_fn_body = self
579550 . infcx
580551 . next_nll_region_var ( NllRegionVariableOrigin :: FreeRegion , || {
@@ -816,7 +787,40 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
816787 DefiningTy :: FnDef ( def_id, _) => {
817788 let sig = tcx. fn_sig ( def_id) . instantiate_identity ( ) ;
818789 let sig = indices. fold_to_region_vids ( tcx, sig) ;
819- sig. inputs_and_output ( )
790+ let inputs_and_output = sig. inputs_and_output ( ) ;
791+
792+ // C-variadic fns also have a `VaList` input that's not listed in the signature
793+ // (as it's created inside the body itself, not passed in from outside).
794+ if self . infcx . tcx . fn_sig ( def_id) . skip_binder ( ) . c_variadic ( ) {
795+ let va_list_did = self
796+ . infcx
797+ . tcx
798+ . require_lang_item ( LangItem :: VaList , self . infcx . tcx . def_span ( self . mir_def ) ) ;
799+
800+ let reg_vid = self
801+ . infcx
802+ . next_nll_region_var ( NllRegionVariableOrigin :: FreeRegion , || {
803+ RegionCtxt :: Free ( sym:: c_dash_variadic)
804+ } )
805+ . as_var ( ) ;
806+
807+ let region = ty:: Region :: new_var ( self . infcx . tcx , reg_vid) ;
808+ let va_list_ty = self
809+ . infcx
810+ . tcx
811+ . type_of ( va_list_did)
812+ . instantiate ( self . infcx . tcx , & [ region. into ( ) ] ) ;
813+
814+ // The signature needs to follow the order [input_tys, va_list_ty, output_ty]
815+ return inputs_and_output. map_bound ( |tys| {
816+ let ( output_ty, input_tys) = tys. split_last ( ) . unwrap ( ) ;
817+ tcx. mk_type_list_from_iter (
818+ input_tys. iter ( ) . copied ( ) . chain ( [ va_list_ty, * output_ty] ) ,
819+ )
820+ } ) ;
821+ }
822+
823+ inputs_and_output
820824 }
821825
822826 DefiningTy :: Const ( def_id, _) => {
0 commit comments