@@ -538,19 +538,21 @@ impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>> for &'tcx
538538/// [`subst_identity`](EarlyBinder::subst_identity) or [`skip_binder`](EarlyBinder::skip_binder).
539539#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
540540#[ derive( Encodable , Decodable , HashStable ) ]
541- pub struct EarlyBinder < T > ( T ) ;
541+ pub struct EarlyBinder < T > {
542+ value : T ,
543+ }
542544
543545/// For early binders, you should first call `subst` before using any visitors.
544546impl < ' tcx , T > !TypeFoldable < TyCtxt < ' tcx > > for ty:: EarlyBinder < T > { }
545547impl < ' tcx , T > !TypeVisitable < TyCtxt < ' tcx > > for ty:: EarlyBinder < T > { }
546548
547549impl < T > EarlyBinder < T > {
548- pub fn bind ( inner : T ) -> EarlyBinder < T > {
549- EarlyBinder ( inner )
550+ pub fn bind ( value : T ) -> EarlyBinder < T > {
551+ EarlyBinder { value }
550552 }
551553
552554 pub fn as_ref ( & self ) -> EarlyBinder < & T > {
553- EarlyBinder ( & self . 0 )
555+ EarlyBinder { value : & self . value }
554556 }
555557
556558 pub fn map_bound_ref < F , U > ( & self , f : F ) -> EarlyBinder < U >
@@ -564,20 +566,20 @@ impl<T> EarlyBinder<T> {
564566 where
565567 F : FnOnce ( T ) -> U ,
566568 {
567- let value = f ( self . 0 ) ;
568- EarlyBinder ( value)
569+ let value = f ( self . value ) ;
570+ EarlyBinder { value }
569571 }
570572
571573 pub fn try_map_bound < F , U , E > ( self , f : F ) -> Result < EarlyBinder < U > , E >
572574 where
573575 F : FnOnce ( T ) -> Result < U , E > ,
574576 {
575- let value = f ( self . 0 ) ?;
576- Ok ( EarlyBinder ( value) )
577+ let value = f ( self . value ) ?;
578+ Ok ( EarlyBinder { value } )
577579 }
578580
579581 pub fn rebind < U > ( & self , value : U ) -> EarlyBinder < U > {
580- EarlyBinder ( value)
582+ EarlyBinder { value }
581583 }
582584
583585 /// Skips the binder and returns the "bound" value.
@@ -592,19 +594,20 @@ impl<T> EarlyBinder<T> {
592594 /// See also [`Binder::skip_binder`](super::Binder::skip_binder), which is
593595 /// the analogous operation on [`super::Binder`].
594596 pub fn skip_binder ( self ) -> T {
595- self . 0
597+ self . value
596598 }
597599}
598600
599601impl < T > EarlyBinder < Option < T > > {
600602 pub fn transpose ( self ) -> Option < EarlyBinder < T > > {
601- self . 0 . map ( |v | EarlyBinder ( v ) )
603+ self . value . map ( |value | EarlyBinder { value } )
602604 }
603605}
604606
605607impl < T , U > EarlyBinder < ( T , U ) > {
606608 pub fn transpose_tuple2 ( self ) -> ( EarlyBinder < T > , EarlyBinder < U > ) {
607- ( EarlyBinder ( self . 0 . 0 ) , EarlyBinder ( self . 0 . 1 ) )
609+ let EarlyBinder { value : ( lhs, rhs) } = self ;
610+ ( EarlyBinder { value : lhs } , EarlyBinder { value : rhs } )
608611 }
609612}
610613
@@ -617,13 +620,13 @@ where
617620 tcx : TyCtxt < ' tcx > ,
618621 substs : & ' s [ GenericArg < ' tcx > ] ,
619622 ) -> SubstIter < ' s , ' tcx , I > {
620- SubstIter { it : self . 0 . into_iter ( ) , tcx, substs }
623+ SubstIter { it : self . value . into_iter ( ) , tcx, substs }
621624 }
622625
623626 /// Similar to [`subst_identity`](EarlyBinder::subst_identity),
624627 /// but on an iterator of `TypeFoldable` values.
625628 pub fn subst_identity_iter ( self ) -> I :: IntoIter {
626- self . 0 . into_iter ( )
629+ self . value . into_iter ( )
627630 }
628631}
629632
@@ -640,7 +643,7 @@ where
640643 type Item = I :: Item ;
641644
642645 fn next ( & mut self ) -> Option < Self :: Item > {
643- Some ( EarlyBinder ( self . it . next ( ) ?) . subst ( self . tcx , self . substs ) )
646+ Some ( EarlyBinder { value : self . it . next ( ) ? } . subst ( self . tcx , self . substs ) )
644647 }
645648
646649 fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -654,7 +657,7 @@ where
654657 I :: Item : TypeFoldable < TyCtxt < ' tcx > > ,
655658{
656659 fn next_back ( & mut self ) -> Option < Self :: Item > {
657- Some ( EarlyBinder ( self . it . next_back ( ) ?) . subst ( self . tcx , self . substs ) )
660+ Some ( EarlyBinder { value : self . it . next_back ( ) ? } . subst ( self . tcx , self . substs ) )
658661 }
659662}
660663
@@ -675,13 +678,13 @@ where
675678 tcx : TyCtxt < ' tcx > ,
676679 substs : & ' s [ GenericArg < ' tcx > ] ,
677680 ) -> SubstIterCopied < ' s , ' tcx , I > {
678- SubstIterCopied { it : self . 0 . into_iter ( ) , tcx, substs }
681+ SubstIterCopied { it : self . value . into_iter ( ) , tcx, substs }
679682 }
680683
681684 /// Similar to [`subst_identity`](EarlyBinder::subst_identity),
682685 /// but on an iterator of values that deref to a `TypeFoldable`.
683686 pub fn subst_identity_iter_copied ( self ) -> impl Iterator < Item = <I :: Item as Deref >:: Target > {
684- self . 0 . into_iter ( ) . map ( |v| * v)
687+ self . value . into_iter ( ) . map ( |v| * v)
685688 }
686689}
687690
@@ -699,7 +702,7 @@ where
699702 type Item = <I :: Item as Deref >:: Target ;
700703
701704 fn next ( & mut self ) -> Option < Self :: Item > {
702- Some ( EarlyBinder ( * self . it . next ( ) ? ) . subst ( self . tcx , self . substs ) )
705+ self . it . next ( ) . map ( |value| EarlyBinder { value : * value } . subst ( self . tcx , self . substs ) )
703706 }
704707
705708 fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -714,7 +717,7 @@ where
714717 <I :: Item as Deref >:: Target : Copy + TypeFoldable < TyCtxt < ' tcx > > ,
715718{
716719 fn next_back ( & mut self ) -> Option < Self :: Item > {
717- Some ( EarlyBinder ( * self . it . next_back ( ) ? ) . subst ( self . tcx , self . substs ) )
720+ self . it . next_back ( ) . map ( |value| EarlyBinder { value : * value } . subst ( self . tcx , self . substs ) )
718721 }
719722}
720723
@@ -732,15 +735,15 @@ pub struct EarlyBinderIter<T> {
732735
733736impl < T : IntoIterator > EarlyBinder < T > {
734737 pub fn transpose_iter ( self ) -> EarlyBinderIter < T :: IntoIter > {
735- EarlyBinderIter { t : self . 0 . into_iter ( ) }
738+ EarlyBinderIter { t : self . value . into_iter ( ) }
736739 }
737740}
738741
739742impl < T : Iterator > Iterator for EarlyBinderIter < T > {
740743 type Item = EarlyBinder < T :: Item > ;
741744
742745 fn next ( & mut self ) -> Option < Self :: Item > {
743- self . t . next ( ) . map ( |i | EarlyBinder ( i ) )
746+ self . t . next ( ) . map ( |value | EarlyBinder { value } )
744747 }
745748
746749 fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -751,7 +754,7 @@ impl<T: Iterator> Iterator for EarlyBinderIter<T> {
751754impl < ' tcx , T : TypeFoldable < TyCtxt < ' tcx > > > ty:: EarlyBinder < T > {
752755 pub fn subst ( self , tcx : TyCtxt < ' tcx > , substs : & [ GenericArg < ' tcx > ] ) -> T {
753756 let mut folder = SubstFolder { tcx, substs, binders_passed : 0 } ;
754- self . 0 . fold_with ( & mut folder)
757+ self . value . fold_with ( & mut folder)
755758 }
756759
757760 /// Makes the identity substitution `T0 => T0, ..., TN => TN`.
@@ -763,12 +766,12 @@ impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>>> ty::EarlyBinder<T> {
763766 /// - Inside of the body of `foo`, we treat `T` as a placeholder by calling
764767 /// `subst_identity` to discharge the `EarlyBinder`.
765768 pub fn subst_identity ( self ) -> T {
766- self . 0
769+ self . value
767770 }
768771
769772 /// Returns the inner value, but only if it contains no bound vars.
770773 pub fn no_bound_vars ( self ) -> Option < T > {
771- if !self . 0 . has_param ( ) { Some ( self . 0 ) } else { None }
774+ if !self . value . has_param ( ) { Some ( self . value ) } else { None }
772775 }
773776}
774777
0 commit comments