@@ -1007,7 +1007,10 @@ impl BoundVariableKind {
1007
1007
/// `Decodable` and `Encodable` are implemented for `Binder<T>` using the `impl_binder_encode_decode!` macro.
1008
1008
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
1009
1009
#[ derive( HashStable , Lift ) ]
1010
- pub struct Binder < ' tcx , T > ( T , & ' tcx List < BoundVariableKind > ) ;
1010
+ pub struct Binder < ' tcx , T > {
1011
+ value : T ,
1012
+ bound_vars : & ' tcx List < BoundVariableKind > ,
1013
+ }
1011
1014
1012
1015
impl < ' tcx , T > Binder < ' tcx , T >
1013
1016
where
@@ -1023,15 +1026,15 @@ where
1023
1026
!value. has_escaping_bound_vars( ) ,
1024
1027
"`{value:?}` has escaping bound vars, so it cannot be wrapped in a dummy binder."
1025
1028
) ;
1026
- Binder ( value, ty:: List :: empty ( ) )
1029
+ Binder { value, bound_vars : ty:: List :: empty ( ) }
1027
1030
}
1028
1031
1029
- pub fn bind_with_vars ( value : T , vars : & ' tcx List < BoundVariableKind > ) -> Binder < ' tcx , T > {
1032
+ pub fn bind_with_vars ( value : T , bound_vars : & ' tcx List < BoundVariableKind > ) -> Binder < ' tcx , T > {
1030
1033
if cfg ! ( debug_assertions) {
1031
- let mut validator = ValidateBoundVars :: new ( vars ) ;
1034
+ let mut validator = ValidateBoundVars :: new ( bound_vars ) ;
1032
1035
value. visit_with ( & mut validator) ;
1033
1036
}
1034
- Binder ( value, vars )
1037
+ Binder { value, bound_vars }
1035
1038
}
1036
1039
}
1037
1040
@@ -1053,30 +1056,30 @@ impl<'tcx, T> Binder<'tcx, T> {
1053
1056
/// - comparing the self type of a PolyTraitRef to see if it is equal to
1054
1057
/// a type parameter `X`, since the type `X` does not reference any regions
1055
1058
pub fn skip_binder ( self ) -> T {
1056
- self . 0
1059
+ self . value
1057
1060
}
1058
1061
1059
1062
pub fn bound_vars ( & self ) -> & ' tcx List < BoundVariableKind > {
1060
- self . 1
1063
+ self . bound_vars
1061
1064
}
1062
1065
1063
1066
pub fn as_ref ( & self ) -> Binder < ' tcx , & T > {
1064
- Binder ( & self . 0 , self . 1 )
1067
+ Binder { value : & self . value , bound_vars : self . bound_vars }
1065
1068
}
1066
1069
1067
1070
pub fn as_deref ( & self ) -> Binder < ' tcx , & T :: Target >
1068
1071
where
1069
1072
T : Deref ,
1070
1073
{
1071
- Binder ( & self . 0 , self . 1 )
1074
+ Binder { value : & self . value , bound_vars : self . bound_vars }
1072
1075
}
1073
1076
1074
1077
pub fn map_bound_ref_unchecked < F , U > ( & self , f : F ) -> Binder < ' tcx , U >
1075
1078
where
1076
1079
F : FnOnce ( & T ) -> U ,
1077
1080
{
1078
- let value = f ( & self . 0 ) ;
1079
- Binder ( value, self . 1 )
1081
+ let value = f ( & self . value ) ;
1082
+ Binder { value, bound_vars : self . bound_vars }
1080
1083
}
1081
1084
1082
1085
pub fn map_bound_ref < F , U : TypeVisitable < TyCtxt < ' tcx > > > ( & self , f : F ) -> Binder < ' tcx , U >
@@ -1090,12 +1093,13 @@ impl<'tcx, T> Binder<'tcx, T> {
1090
1093
where
1091
1094
F : FnOnce ( T ) -> U ,
1092
1095
{
1093
- let value = f ( self . 0 ) ;
1096
+ let Binder { value, bound_vars } = self ;
1097
+ let value = f ( value) ;
1094
1098
if cfg ! ( debug_assertions) {
1095
- let mut validator = ValidateBoundVars :: new ( self . 1 ) ;
1099
+ let mut validator = ValidateBoundVars :: new ( bound_vars ) ;
1096
1100
value. visit_with ( & mut validator) ;
1097
1101
}
1098
- Binder ( value, self . 1 )
1102
+ Binder { value, bound_vars }
1099
1103
}
1100
1104
1101
1105
pub fn try_map_bound < F , U : TypeVisitable < TyCtxt < ' tcx > > , E > (
@@ -1105,12 +1109,13 @@ impl<'tcx, T> Binder<'tcx, T> {
1105
1109
where
1106
1110
F : FnOnce ( T ) -> Result < U , E > ,
1107
1111
{
1108
- let value = f ( self . 0 ) ?;
1112
+ let Binder { value, bound_vars } = self ;
1113
+ let value = f ( value) ?;
1109
1114
if cfg ! ( debug_assertions) {
1110
- let mut validator = ValidateBoundVars :: new ( self . 1 ) ;
1115
+ let mut validator = ValidateBoundVars :: new ( bound_vars ) ;
1111
1116
value. visit_with ( & mut validator) ;
1112
1117
}
1113
- Ok ( Binder ( value, self . 1 ) )
1118
+ Ok ( Binder { value, bound_vars } )
1114
1119
}
1115
1120
1116
1121
/// Wraps a `value` in a binder, using the same bound variables as the
@@ -1126,11 +1131,7 @@ impl<'tcx, T> Binder<'tcx, T> {
1126
1131
where
1127
1132
U : TypeVisitable < TyCtxt < ' tcx > > ,
1128
1133
{
1129
- if cfg ! ( debug_assertions) {
1130
- let mut validator = ValidateBoundVars :: new ( self . bound_vars ( ) ) ;
1131
- value. visit_with ( & mut validator) ;
1132
- }
1133
- Binder ( value, self . 1 )
1134
+ Binder :: bind_with_vars ( value, self . bound_vars )
1134
1135
}
1135
1136
1136
1137
/// Unwraps and returns the value within, but only if it contains
@@ -1147,7 +1148,7 @@ impl<'tcx, T> Binder<'tcx, T> {
1147
1148
where
1148
1149
T : TypeVisitable < TyCtxt < ' tcx > > ,
1149
1150
{
1150
- if self . 0 . has_escaping_bound_vars ( ) { None } else { Some ( self . skip_binder ( ) ) }
1151
+ if self . value . has_escaping_bound_vars ( ) { None } else { Some ( self . skip_binder ( ) ) }
1151
1152
}
1152
1153
1153
1154
/// Splits the contents into two things that share the same binder
@@ -1160,22 +1161,23 @@ impl<'tcx, T> Binder<'tcx, T> {
1160
1161
where
1161
1162
F : FnOnce ( T ) -> ( U , V ) ,
1162
1163
{
1163
- let ( u, v) = f ( self . 0 ) ;
1164
- ( Binder ( u, self . 1 ) , Binder ( v, self . 1 ) )
1164
+ let Binder { value, bound_vars } = self ;
1165
+ let ( u, v) = f ( value) ;
1166
+ ( Binder { value : u, bound_vars } , Binder { value : v, bound_vars } )
1165
1167
}
1166
1168
}
1167
1169
1168
1170
impl < ' tcx , T > Binder < ' tcx , Option < T > > {
1169
1171
pub fn transpose ( self ) -> Option < Binder < ' tcx , T > > {
1170
- let bound_vars = self . 1 ;
1171
- self . 0 . map ( |v | Binder ( v , bound_vars) )
1172
+ let Binder { value , bound_vars } = self ;
1173
+ value . map ( |value | Binder { value , bound_vars } )
1172
1174
}
1173
1175
}
1174
1176
1175
1177
impl < ' tcx , T : IntoIterator > Binder < ' tcx , T > {
1176
1178
pub fn iter ( self ) -> impl Iterator < Item = ty:: Binder < ' tcx , T :: Item > > {
1177
- let bound_vars = self . 1 ;
1178
- self . 0 . into_iter ( ) . map ( |v | Binder ( v , bound_vars) )
1179
+ let Binder { value , bound_vars } = self ;
1180
+ value . into_iter ( ) . map ( |value | Binder { value , bound_vars } )
1179
1181
}
1180
1182
}
1181
1183
@@ -1184,7 +1186,7 @@ where
1184
1186
T : IntoDiagnosticArg ,
1185
1187
{
1186
1188
fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
1187
- self . 0 . into_diagnostic_arg ( )
1189
+ self . value . into_diagnostic_arg ( )
1188
1190
}
1189
1191
}
1190
1192
0 commit comments