@@ -39,6 +39,7 @@ use super::GenericParamDefKind;
3939pub type TyKind < ' tcx > = ir:: TyKind < TyCtxt < ' tcx > > ;
4040pub type TypeAndMut < ' tcx > = ir:: TypeAndMut < TyCtxt < ' tcx > > ;
4141pub type AliasTy < ' tcx > = ir:: AliasTy < TyCtxt < ' tcx > > ;
42+ pub type FnSig < ' tcx > = ir:: FnSig < TyCtxt < ' tcx > > ;
4243
4344pub trait Article {
4445 fn article ( & self ) -> & ' static str ;
@@ -985,14 +986,6 @@ impl<'tcx, T> Binder<'tcx, T> {
985986 Binder { value : & self . value , bound_vars : self . bound_vars }
986987 }
987988
988- pub fn map_bound_ref_unchecked < F , U > ( & self , f : F ) -> Binder < ' tcx , U >
989- where
990- F : FnOnce ( & T ) -> U ,
991- {
992- let value = f ( & self . value ) ;
993- Binder { value, bound_vars : self . bound_vars }
994- }
995-
996989 pub fn map_bound_ref < F , U : TypeVisitable < TyCtxt < ' tcx > > > ( & self , f : F ) -> Binder < ' tcx , U >
997990 where
998991 F : FnOnce ( & T ) -> U ,
@@ -1109,73 +1102,37 @@ pub struct GenSig<'tcx> {
11091102 pub return_ty : Ty < ' tcx > ,
11101103}
11111104
1112- /// Signature of a function type, which we have arbitrarily
1113- /// decided to use to refer to the input/output types.
1114- ///
1115- /// - `inputs`: is the list of arguments and their modes.
1116- /// - `output`: is the return type.
1117- /// - `c_variadic`: indicates whether this is a C-variadic function.
1118- #[ derive( Copy , Clone , PartialEq , Eq , Hash , TyEncodable , TyDecodable ) ]
1119- #[ derive( HashStable , TypeFoldable , TypeVisitable , Lift ) ]
1120- pub struct FnSig < ' tcx > {
1121- pub inputs_and_output : & ' tcx List < Ty < ' tcx > > ,
1122- pub c_variadic : bool ,
1123- pub unsafety : hir:: Unsafety ,
1124- pub abi : abi:: Abi ,
1125- }
1126-
1127- impl < ' tcx > FnSig < ' tcx > {
1128- pub fn inputs ( & self ) -> & ' tcx [ Ty < ' tcx > ] {
1129- & self . inputs_and_output [ ..self . inputs_and_output . len ( ) - 1 ]
1130- }
1131-
1132- pub fn output ( & self ) -> Ty < ' tcx > {
1133- self . inputs_and_output [ self . inputs_and_output . len ( ) - 1 ]
1134- }
1135-
1136- // Creates a minimal `FnSig` to be used when encountering a `TyKind::Error` in a fallible
1137- // method.
1138- fn fake ( ) -> FnSig < ' tcx > {
1139- FnSig {
1140- inputs_and_output : List :: empty ( ) ,
1141- c_variadic : false ,
1142- unsafety : hir:: Unsafety :: Normal ,
1143- abi : abi:: Abi :: Rust ,
1144- }
1145- }
1146- }
1147-
1148- impl < ' tcx > IntoDiagArg for FnSig < ' tcx > {
1149- fn into_diag_arg ( self ) -> DiagArgValue {
1150- self . to_string ( ) . into_diag_arg ( )
1151- }
1152- }
1153-
11541105pub type PolyFnSig < ' tcx > = Binder < ' tcx , FnSig < ' tcx > > ;
11551106
11561107impl < ' tcx > PolyFnSig < ' tcx > {
11571108 #[ inline]
11581109 pub fn inputs ( & self ) -> Binder < ' tcx , & ' tcx [ Ty < ' tcx > ] > {
1159- self . map_bound_ref_unchecked ( |fn_sig| fn_sig. inputs ( ) )
1110+ self . map_bound_ref ( |fn_sig| fn_sig. inputs ( ) )
11601111 }
1112+
11611113 #[ inline]
11621114 #[ track_caller]
11631115 pub fn input ( & self , index : usize ) -> ty:: Binder < ' tcx , Ty < ' tcx > > {
11641116 self . map_bound_ref ( |fn_sig| fn_sig. inputs ( ) [ index] )
11651117 }
1118+
11661119 pub fn inputs_and_output ( & self ) -> ty:: Binder < ' tcx , & ' tcx List < Ty < ' tcx > > > {
11671120 self . map_bound_ref ( |fn_sig| fn_sig. inputs_and_output )
11681121 }
1122+
11691123 #[ inline]
11701124 pub fn output ( & self ) -> ty:: Binder < ' tcx , Ty < ' tcx > > {
11711125 self . map_bound_ref ( |fn_sig| fn_sig. output ( ) )
11721126 }
1127+
11731128 pub fn c_variadic ( & self ) -> bool {
11741129 self . skip_binder ( ) . c_variadic
11751130 }
1131+
11761132 pub fn unsafety ( & self ) -> hir:: Unsafety {
11771133 self . skip_binder ( ) . unsafety
11781134 }
1135+
11791136 pub fn abi ( & self ) -> abi:: Abi {
11801137 self . skip_binder ( ) . abi
11811138 }
@@ -2031,7 +1988,12 @@ impl<'tcx> Ty<'tcx> {
20311988 FnPtr ( f) => * f,
20321989 Error ( _) => {
20331990 // ignore errors (#54954)
2034- ty:: Binder :: dummy ( FnSig :: fake ( ) )
1991+ ty:: Binder :: dummy ( ty:: FnSig {
1992+ inputs_and_output : ty:: List :: empty ( ) ,
1993+ c_variadic : false ,
1994+ unsafety : hir:: Unsafety :: Normal ,
1995+ abi : abi:: Abi :: Rust ,
1996+ } )
20351997 }
20361998 Closure ( ..) => bug ! (
20371999 "to get the signature of a closure, use `args.as_closure().sig()` not `fn_sig()`" ,
@@ -2624,6 +2586,13 @@ impl<'tcx> Ty<'tcx> {
26242586 }
26252587}
26262588
2589+ impl < ' tcx > rustc_type_ir:: inherent:: Tys < TyCtxt < ' tcx > > for & ' tcx ty:: List < Ty < ' tcx > > {
2590+ fn split_inputs_and_output ( self ) -> ( & ' tcx [ Ty < ' tcx > ] , Ty < ' tcx > ) {
2591+ let ( output, inputs) = self . split_last ( ) . unwrap ( ) ;
2592+ ( inputs, * output)
2593+ }
2594+ }
2595+
26272596/// Extra information about why we ended up with a particular variance.
26282597/// This is only used to add more information to error messages, and
26292598/// has no effect on soundness. While choosing the 'wrong' `VarianceDiagInfo`
0 commit comments