@@ -39,6 +39,7 @@ use super::GenericParamDefKind;
39
39
pub type TyKind < ' tcx > = ir:: TyKind < TyCtxt < ' tcx > > ;
40
40
pub type TypeAndMut < ' tcx > = ir:: TypeAndMut < TyCtxt < ' tcx > > ;
41
41
pub type AliasTy < ' tcx > = ir:: AliasTy < TyCtxt < ' tcx > > ;
42
+ pub type FnSig < ' tcx > = ir:: FnSig < TyCtxt < ' tcx > > ;
42
43
43
44
pub trait Article {
44
45
fn article ( & self ) -> & ' static str ;
@@ -985,14 +986,6 @@ impl<'tcx, T> Binder<'tcx, T> {
985
986
Binder { value : & self . value , bound_vars : self . bound_vars }
986
987
}
987
988
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
-
996
989
pub fn map_bound_ref < F , U : TypeVisitable < TyCtxt < ' tcx > > > ( & self , f : F ) -> Binder < ' tcx , U >
997
990
where
998
991
F : FnOnce ( & T ) -> U ,
@@ -1109,73 +1102,37 @@ pub struct GenSig<'tcx> {
1109
1102
pub return_ty : Ty < ' tcx > ,
1110
1103
}
1111
1104
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
-
1154
1105
pub type PolyFnSig < ' tcx > = Binder < ' tcx , FnSig < ' tcx > > ;
1155
1106
1156
1107
impl < ' tcx > PolyFnSig < ' tcx > {
1157
1108
#[ inline]
1158
1109
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 ( ) )
1160
1111
}
1112
+
1161
1113
#[ inline]
1162
1114
#[ track_caller]
1163
1115
pub fn input ( & self , index : usize ) -> ty:: Binder < ' tcx , Ty < ' tcx > > {
1164
1116
self . map_bound_ref ( |fn_sig| fn_sig. inputs ( ) [ index] )
1165
1117
}
1118
+
1166
1119
pub fn inputs_and_output ( & self ) -> ty:: Binder < ' tcx , & ' tcx List < Ty < ' tcx > > > {
1167
1120
self . map_bound_ref ( |fn_sig| fn_sig. inputs_and_output )
1168
1121
}
1122
+
1169
1123
#[ inline]
1170
1124
pub fn output ( & self ) -> ty:: Binder < ' tcx , Ty < ' tcx > > {
1171
1125
self . map_bound_ref ( |fn_sig| fn_sig. output ( ) )
1172
1126
}
1127
+
1173
1128
pub fn c_variadic ( & self ) -> bool {
1174
1129
self . skip_binder ( ) . c_variadic
1175
1130
}
1131
+
1176
1132
pub fn unsafety ( & self ) -> hir:: Unsafety {
1177
1133
self . skip_binder ( ) . unsafety
1178
1134
}
1135
+
1179
1136
pub fn abi ( & self ) -> abi:: Abi {
1180
1137
self . skip_binder ( ) . abi
1181
1138
}
@@ -2031,7 +1988,12 @@ impl<'tcx> Ty<'tcx> {
2031
1988
FnPtr ( f) => * f,
2032
1989
Error ( _) => {
2033
1990
// 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
+ } )
2035
1997
}
2036
1998
Closure ( ..) => bug ! (
2037
1999
"to get the signature of a closure, use `args.as_closure().sig()` not `fn_sig()`" ,
@@ -2624,6 +2586,13 @@ impl<'tcx> Ty<'tcx> {
2624
2586
}
2625
2587
}
2626
2588
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
+
2627
2596
/// Extra information about why we ended up with a particular variance.
2628
2597
/// This is only used to add more information to error messages, and
2629
2598
/// has no effect on soundness. While choosing the 'wrong' `VarianceDiagInfo`
0 commit comments