@@ -6,7 +6,6 @@ use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts};
66use crate :: ty:: visit:: { TypeVisitable , TypeVisitor } ;
77use crate :: ty:: { self , Lift , List , ParamConst , Ty , TyCtxt } ;
88
9- use rustc_data_structures:: captures:: Captures ;
109use rustc_data_structures:: intern:: { Interned , WithStableHash } ;
1110use rustc_hir:: def_id:: DefId ;
1211use rustc_macros:: HashStable ;
@@ -19,7 +18,7 @@ use std::fmt;
1918use std:: marker:: PhantomData ;
2019use std:: mem;
2120use std:: num:: NonZeroUsize ;
22- use std:: ops:: ControlFlow ;
21+ use std:: ops:: { ControlFlow , Deref } ;
2322use std:: slice;
2423
2524/// An entity in the Rust type system, which can be one of
@@ -562,25 +561,86 @@ impl<T, U> EarlyBinder<(T, U)> {
562561 }
563562}
564563
565- impl < ' tcx , ' s , T : IntoIterator < Item = I > , I : TypeFoldable < ' tcx > > EarlyBinder < T > {
564+ impl < ' tcx , ' s , I : IntoIterator > EarlyBinder < I >
565+ where
566+ I :: Item : TypeFoldable < ' tcx > ,
567+ {
566568 pub fn subst_iter (
567569 self ,
568570 tcx : TyCtxt < ' tcx > ,
569571 substs : & ' s [ GenericArg < ' tcx > ] ,
570- ) -> impl Iterator < Item = I > + Captures < ' s > + Captures < ' tcx > {
571- self . 0 . into_iter ( ) . map ( move |t| EarlyBinder ( t) . subst ( tcx, substs) )
572+ ) -> SubstIter < ' s , ' tcx , I > {
573+ SubstIter { it : self . 0 . into_iter ( ) , tcx, substs }
574+ }
575+ }
576+
577+ pub struct SubstIter < ' s , ' tcx , I : IntoIterator > {
578+ it : I :: IntoIter ,
579+ tcx : TyCtxt < ' tcx > ,
580+ substs : & ' s [ GenericArg < ' tcx > ] ,
581+ }
582+
583+ impl < ' tcx , I : IntoIterator > Iterator for SubstIter < ' _ , ' tcx , I >
584+ where
585+ I :: Item : TypeFoldable < ' tcx > ,
586+ {
587+ type Item = I :: Item ;
588+
589+ fn next ( & mut self ) -> Option < Self :: Item > {
590+ Some ( EarlyBinder ( self . it . next ( ) ?) . subst ( self . tcx , self . substs ) )
591+ }
592+ }
593+
594+ impl < ' tcx , I : IntoIterator > DoubleEndedIterator for SubstIter < ' _ , ' tcx , I >
595+ where
596+ I :: IntoIter : DoubleEndedIterator ,
597+ I :: Item : TypeFoldable < ' tcx > ,
598+ {
599+ fn next_back ( & mut self ) -> Option < Self :: Item > {
600+ Some ( EarlyBinder ( self . it . next_back ( ) ?) . subst ( self . tcx , self . substs ) )
572601 }
573602}
574603
575- impl < ' tcx , ' s , ' a , T : IntoIterator < Item = & ' a I > , I : Copy + TypeFoldable < ' tcx > + ' a >
576- EarlyBinder < T >
604+ impl < ' tcx , ' s , I : IntoIterator > EarlyBinder < I >
605+ where
606+ I :: Item : Deref ,
607+ <I :: Item as Deref >:: Target : Copy + TypeFoldable < ' tcx > ,
577608{
578609 pub fn subst_iter_copied (
579610 self ,
580611 tcx : TyCtxt < ' tcx > ,
581612 substs : & ' s [ GenericArg < ' tcx > ] ,
582- ) -> impl Iterator < Item = I > + Captures < ' s > + Captures < ' tcx > + Captures < ' a > {
583- self . 0 . into_iter ( ) . map ( move |t| EarlyBinder ( * t) . subst ( tcx, substs) )
613+ ) -> SubstIterCopied < ' s , ' tcx , I > {
614+ SubstIterCopied { it : self . 0 . into_iter ( ) , tcx, substs }
615+ }
616+ }
617+
618+ pub struct SubstIterCopied < ' a , ' tcx , I : IntoIterator > {
619+ it : I :: IntoIter ,
620+ tcx : TyCtxt < ' tcx > ,
621+ substs : & ' a [ GenericArg < ' tcx > ] ,
622+ }
623+
624+ impl < ' tcx , I : IntoIterator > Iterator for SubstIterCopied < ' _ , ' tcx , I >
625+ where
626+ I :: Item : Deref ,
627+ <I :: Item as Deref >:: Target : Copy + TypeFoldable < ' tcx > ,
628+ {
629+ type Item = <I :: Item as Deref >:: Target ;
630+
631+ fn next ( & mut self ) -> Option < Self :: Item > {
632+ Some ( EarlyBinder ( * self . it . next ( ) ?) . subst ( self . tcx , self . substs ) )
633+ }
634+ }
635+
636+ impl < ' tcx , I : IntoIterator > DoubleEndedIterator for SubstIterCopied < ' _ , ' tcx , I >
637+ where
638+ I :: IntoIter : DoubleEndedIterator ,
639+ I :: Item : Deref ,
640+ <I :: Item as Deref >:: Target : Copy + TypeFoldable < ' tcx > ,
641+ {
642+ fn next_back ( & mut self ) -> Option < Self :: Item > {
643+ Some ( EarlyBinder ( * self . it . next_back ( ) ?) . subst ( self . tcx , self . substs ) )
584644 }
585645}
586646
0 commit comments