@@ -6,7 +6,6 @@ use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts};
6
6
use crate :: ty:: visit:: { TypeVisitable , TypeVisitor } ;
7
7
use crate :: ty:: { self , Lift , List , ParamConst , Ty , TyCtxt } ;
8
8
9
- use rustc_data_structures:: captures:: Captures ;
10
9
use rustc_data_structures:: intern:: { Interned , WithStableHash } ;
11
10
use rustc_hir:: def_id:: DefId ;
12
11
use rustc_macros:: HashStable ;
@@ -19,7 +18,7 @@ use std::fmt;
19
18
use std:: marker:: PhantomData ;
20
19
use std:: mem;
21
20
use std:: num:: NonZeroUsize ;
22
- use std:: ops:: ControlFlow ;
21
+ use std:: ops:: { ControlFlow , Deref } ;
23
22
use std:: slice;
24
23
25
24
/// An entity in the Rust type system, which can be one of
@@ -562,25 +561,86 @@ impl<T, U> EarlyBinder<(T, U)> {
562
561
}
563
562
}
564
563
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
+ {
566
568
pub fn subst_iter (
567
569
self ,
568
570
tcx : TyCtxt < ' tcx > ,
569
571
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 ) )
572
601
}
573
602
}
574
603
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 > ,
577
608
{
578
609
pub fn subst_iter_copied (
579
610
self ,
580
611
tcx : TyCtxt < ' tcx > ,
581
612
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 ) )
584
644
}
585
645
}
586
646
0 commit comments