@@ -538,19 +538,21 @@ impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>> for &'tcx
538
538
/// [`subst_identity`](EarlyBinder::subst_identity) or [`skip_binder`](EarlyBinder::skip_binder).
539
539
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
540
540
#[ derive( Encodable , Decodable , HashStable ) ]
541
- pub struct EarlyBinder < T > ( T ) ;
541
+ pub struct EarlyBinder < T > {
542
+ value : T ,
543
+ }
542
544
543
545
/// For early binders, you should first call `subst` before using any visitors.
544
546
impl < ' tcx , T > !TypeFoldable < TyCtxt < ' tcx > > for ty:: EarlyBinder < T > { }
545
547
impl < ' tcx , T > !TypeVisitable < TyCtxt < ' tcx > > for ty:: EarlyBinder < T > { }
546
548
547
549
impl < 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 }
550
552
}
551
553
552
554
pub fn as_ref ( & self ) -> EarlyBinder < & T > {
553
- EarlyBinder ( & self . 0 )
555
+ EarlyBinder { value : & self . value }
554
556
}
555
557
556
558
pub fn map_bound_ref < F , U > ( & self , f : F ) -> EarlyBinder < U >
@@ -564,20 +566,20 @@ impl<T> EarlyBinder<T> {
564
566
where
565
567
F : FnOnce ( T ) -> U ,
566
568
{
567
- let value = f ( self . 0 ) ;
568
- EarlyBinder ( value)
569
+ let value = f ( self . value ) ;
570
+ EarlyBinder { value }
569
571
}
570
572
571
573
pub fn try_map_bound < F , U , E > ( self , f : F ) -> Result < EarlyBinder < U > , E >
572
574
where
573
575
F : FnOnce ( T ) -> Result < U , E > ,
574
576
{
575
- let value = f ( self . 0 ) ?;
576
- Ok ( EarlyBinder ( value) )
577
+ let value = f ( self . value ) ?;
578
+ Ok ( EarlyBinder { value } )
577
579
}
578
580
579
581
pub fn rebind < U > ( & self , value : U ) -> EarlyBinder < U > {
580
- EarlyBinder ( value)
582
+ EarlyBinder { value }
581
583
}
582
584
583
585
/// Skips the binder and returns the "bound" value.
@@ -592,19 +594,20 @@ impl<T> EarlyBinder<T> {
592
594
/// See also [`Binder::skip_binder`](super::Binder::skip_binder), which is
593
595
/// the analogous operation on [`super::Binder`].
594
596
pub fn skip_binder ( self ) -> T {
595
- self . 0
597
+ self . value
596
598
}
597
599
}
598
600
599
601
impl < T > EarlyBinder < Option < T > > {
600
602
pub fn transpose ( self ) -> Option < EarlyBinder < T > > {
601
- self . 0 . map ( |v | EarlyBinder ( v ) )
603
+ self . value . map ( |value | EarlyBinder { value } )
602
604
}
603
605
}
604
606
605
607
impl < T , U > EarlyBinder < ( T , U ) > {
606
608
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 } )
608
611
}
609
612
}
610
613
@@ -617,13 +620,13 @@ where
617
620
tcx : TyCtxt < ' tcx > ,
618
621
substs : & ' s [ GenericArg < ' tcx > ] ,
619
622
) -> SubstIter < ' s , ' tcx , I > {
620
- SubstIter { it : self . 0 . into_iter ( ) , tcx, substs }
623
+ SubstIter { it : self . value . into_iter ( ) , tcx, substs }
621
624
}
622
625
623
626
/// Similar to [`subst_identity`](EarlyBinder::subst_identity),
624
627
/// but on an iterator of `TypeFoldable` values.
625
628
pub fn subst_identity_iter ( self ) -> I :: IntoIter {
626
- self . 0 . into_iter ( )
629
+ self . value . into_iter ( )
627
630
}
628
631
}
629
632
@@ -640,7 +643,7 @@ where
640
643
type Item = I :: Item ;
641
644
642
645
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 ) )
644
647
}
645
648
646
649
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -654,7 +657,7 @@ where
654
657
I :: Item : TypeFoldable < TyCtxt < ' tcx > > ,
655
658
{
656
659
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 ) )
658
661
}
659
662
}
660
663
@@ -675,13 +678,13 @@ where
675
678
tcx : TyCtxt < ' tcx > ,
676
679
substs : & ' s [ GenericArg < ' tcx > ] ,
677
680
) -> SubstIterCopied < ' s , ' tcx , I > {
678
- SubstIterCopied { it : self . 0 . into_iter ( ) , tcx, substs }
681
+ SubstIterCopied { it : self . value . into_iter ( ) , tcx, substs }
679
682
}
680
683
681
684
/// Similar to [`subst_identity`](EarlyBinder::subst_identity),
682
685
/// but on an iterator of values that deref to a `TypeFoldable`.
683
686
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)
685
688
}
686
689
}
687
690
@@ -699,7 +702,7 @@ where
699
702
type Item = <I :: Item as Deref >:: Target ;
700
703
701
704
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 ) )
703
706
}
704
707
705
708
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -714,7 +717,7 @@ where
714
717
<I :: Item as Deref >:: Target : Copy + TypeFoldable < TyCtxt < ' tcx > > ,
715
718
{
716
719
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 ) )
718
721
}
719
722
}
720
723
@@ -732,15 +735,15 @@ pub struct EarlyBinderIter<T> {
732
735
733
736
impl < T : IntoIterator > EarlyBinder < T > {
734
737
pub fn transpose_iter ( self ) -> EarlyBinderIter < T :: IntoIter > {
735
- EarlyBinderIter { t : self . 0 . into_iter ( ) }
738
+ EarlyBinderIter { t : self . value . into_iter ( ) }
736
739
}
737
740
}
738
741
739
742
impl < T : Iterator > Iterator for EarlyBinderIter < T > {
740
743
type Item = EarlyBinder < T :: Item > ;
741
744
742
745
fn next ( & mut self ) -> Option < Self :: Item > {
743
- self . t . next ( ) . map ( |i | EarlyBinder ( i ) )
746
+ self . t . next ( ) . map ( |value | EarlyBinder { value } )
744
747
}
745
748
746
749
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -751,7 +754,7 @@ impl<T: Iterator> Iterator for EarlyBinderIter<T> {
751
754
impl < ' tcx , T : TypeFoldable < TyCtxt < ' tcx > > > ty:: EarlyBinder < T > {
752
755
pub fn subst ( self , tcx : TyCtxt < ' tcx > , substs : & [ GenericArg < ' tcx > ] ) -> T {
753
756
let mut folder = SubstFolder { tcx, substs, binders_passed : 0 } ;
754
- self . 0 . fold_with ( & mut folder)
757
+ self . value . fold_with ( & mut folder)
755
758
}
756
759
757
760
/// Makes the identity substitution `T0 => T0, ..., TN => TN`.
@@ -763,12 +766,12 @@ impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>>> ty::EarlyBinder<T> {
763
766
/// - Inside of the body of `foo`, we treat `T` as a placeholder by calling
764
767
/// `subst_identity` to discharge the `EarlyBinder`.
765
768
pub fn subst_identity ( self ) -> T {
766
- self . 0
769
+ self . value
767
770
}
768
771
769
772
/// Returns the inner value, but only if it contains no bound vars.
770
773
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 }
772
775
}
773
776
}
774
777
0 commit comments