@@ -1007,7 +1007,10 @@ impl BoundVariableKind {
10071007/// `Decodable` and `Encodable` are implemented for `Binder<T>` using the `impl_binder_encode_decode!` macro.
10081008#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
10091009#[ 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+ }
10111014
10121015impl < ' tcx , T > Binder < ' tcx , T >
10131016where
@@ -1023,15 +1026,15 @@ where
10231026 !value. has_escaping_bound_vars( ) ,
10241027 "`{value:?}` has escaping bound vars, so it cannot be wrapped in a dummy binder."
10251028 ) ;
1026- Binder ( value, ty:: List :: empty ( ) )
1029+ Binder { value, bound_vars : ty:: List :: empty ( ) }
10271030 }
10281031
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 > {
10301033 if cfg ! ( debug_assertions) {
1031- let mut validator = ValidateBoundVars :: new ( vars ) ;
1034+ let mut validator = ValidateBoundVars :: new ( bound_vars ) ;
10321035 value. visit_with ( & mut validator) ;
10331036 }
1034- Binder ( value, vars )
1037+ Binder { value, bound_vars }
10351038 }
10361039}
10371040
@@ -1053,30 +1056,30 @@ impl<'tcx, T> Binder<'tcx, T> {
10531056 /// - comparing the self type of a PolyTraitRef to see if it is equal to
10541057 /// a type parameter `X`, since the type `X` does not reference any regions
10551058 pub fn skip_binder ( self ) -> T {
1056- self . 0
1059+ self . value
10571060 }
10581061
10591062 pub fn bound_vars ( & self ) -> & ' tcx List < BoundVariableKind > {
1060- self . 1
1063+ self . bound_vars
10611064 }
10621065
10631066 pub fn as_ref ( & self ) -> Binder < ' tcx , & T > {
1064- Binder ( & self . 0 , self . 1 )
1067+ Binder { value : & self . value , bound_vars : self . bound_vars }
10651068 }
10661069
10671070 pub fn as_deref ( & self ) -> Binder < ' tcx , & T :: Target >
10681071 where
10691072 T : Deref ,
10701073 {
1071- Binder ( & self . 0 , self . 1 )
1074+ Binder { value : & self . value , bound_vars : self . bound_vars }
10721075 }
10731076
10741077 pub fn map_bound_ref_unchecked < F , U > ( & self , f : F ) -> Binder < ' tcx , U >
10751078 where
10761079 F : FnOnce ( & T ) -> U ,
10771080 {
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 }
10801083 }
10811084
10821085 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> {
10901093 where
10911094 F : FnOnce ( T ) -> U ,
10921095 {
1093- let value = f ( self . 0 ) ;
1096+ let Binder { value, bound_vars } = self ;
1097+ let value = f ( value) ;
10941098 if cfg ! ( debug_assertions) {
1095- let mut validator = ValidateBoundVars :: new ( self . 1 ) ;
1099+ let mut validator = ValidateBoundVars :: new ( bound_vars ) ;
10961100 value. visit_with ( & mut validator) ;
10971101 }
1098- Binder ( value, self . 1 )
1102+ Binder { value, bound_vars }
10991103 }
11001104
11011105 pub fn try_map_bound < F , U : TypeVisitable < TyCtxt < ' tcx > > , E > (
@@ -1105,12 +1109,13 @@ impl<'tcx, T> Binder<'tcx, T> {
11051109 where
11061110 F : FnOnce ( T ) -> Result < U , E > ,
11071111 {
1108- let value = f ( self . 0 ) ?;
1112+ let Binder { value, bound_vars } = self ;
1113+ let value = f ( value) ?;
11091114 if cfg ! ( debug_assertions) {
1110- let mut validator = ValidateBoundVars :: new ( self . 1 ) ;
1115+ let mut validator = ValidateBoundVars :: new ( bound_vars ) ;
11111116 value. visit_with ( & mut validator) ;
11121117 }
1113- Ok ( Binder ( value, self . 1 ) )
1118+ Ok ( Binder { value, bound_vars } )
11141119 }
11151120
11161121 /// Wraps a `value` in a binder, using the same bound variables as the
@@ -1126,11 +1131,7 @@ impl<'tcx, T> Binder<'tcx, T> {
11261131 where
11271132 U : TypeVisitable < TyCtxt < ' tcx > > ,
11281133 {
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 )
11341135 }
11351136
11361137 /// Unwraps and returns the value within, but only if it contains
@@ -1147,7 +1148,7 @@ impl<'tcx, T> Binder<'tcx, T> {
11471148 where
11481149 T : TypeVisitable < TyCtxt < ' tcx > > ,
11491150 {
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 ( ) ) }
11511152 }
11521153
11531154 /// Splits the contents into two things that share the same binder
@@ -1160,22 +1161,23 @@ impl<'tcx, T> Binder<'tcx, T> {
11601161 where
11611162 F : FnOnce ( T ) -> ( U , V ) ,
11621163 {
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 } )
11651167 }
11661168}
11671169
11681170impl < ' tcx , T > Binder < ' tcx , Option < T > > {
11691171 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 } )
11721174 }
11731175}
11741176
11751177impl < ' tcx , T : IntoIterator > Binder < ' tcx , T > {
11761178 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 } )
11791181 }
11801182}
11811183
@@ -1184,7 +1186,7 @@ where
11841186 T : IntoDiagnosticArg ,
11851187{
11861188 fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
1187- self . 0 . into_diagnostic_arg ( )
1189+ self . value . into_diagnostic_arg ( )
11881190 }
11891191}
11901192
0 commit comments