@@ -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
@@ -559,25 +558,86 @@ impl<T, U> EarlyBinder<(T, U)> {
559
558
}
560
559
}
561
560
562
- impl < ' tcx , ' s , T : IntoIterator < Item = I > , I : TypeFoldable < ' tcx > > EarlyBinder < T > {
561
+ impl < ' tcx , ' s , I : IntoIterator > EarlyBinder < I >
562
+ where
563
+ I :: Item : TypeFoldable < ' tcx > ,
564
+ {
563
565
pub fn subst_iter (
564
566
self ,
565
567
tcx : TyCtxt < ' tcx > ,
566
568
substs : & ' s [ GenericArg < ' tcx > ] ,
567
- ) -> impl Iterator < Item = I > + Captures < ' s > + Captures < ' tcx > {
568
- self . 0 . into_iter ( ) . map ( move |t| EarlyBinder ( t) . subst ( tcx, substs) )
569
+ ) -> SubstIter < ' s , ' tcx , I > {
570
+ SubstIter { it : self . 0 . into_iter ( ) , tcx, substs }
571
+ }
572
+ }
573
+
574
+ pub struct SubstIter < ' s , ' tcx , I : IntoIterator > {
575
+ it : I :: IntoIter ,
576
+ tcx : TyCtxt < ' tcx > ,
577
+ substs : & ' s [ GenericArg < ' tcx > ] ,
578
+ }
579
+
580
+ impl < ' tcx , I : IntoIterator > Iterator for SubstIter < ' _ , ' tcx , I >
581
+ where
582
+ I :: Item : TypeFoldable < ' tcx > ,
583
+ {
584
+ type Item = I :: Item ;
585
+
586
+ fn next ( & mut self ) -> Option < Self :: Item > {
587
+ Some ( EarlyBinder ( self . it . next ( ) ?) . subst ( self . tcx , self . substs ) )
588
+ }
589
+ }
590
+
591
+ impl < ' tcx , I : IntoIterator > DoubleEndedIterator for SubstIter < ' _ , ' tcx , I >
592
+ where
593
+ I :: IntoIter : DoubleEndedIterator ,
594
+ I :: Item : TypeFoldable < ' tcx > ,
595
+ {
596
+ fn next_back ( & mut self ) -> Option < Self :: Item > {
597
+ Some ( EarlyBinder ( self . it . next_back ( ) ?) . subst ( self . tcx , self . substs ) )
569
598
}
570
599
}
571
600
572
- impl < ' tcx , ' s , ' a , T : IntoIterator < Item = & ' a I > , I : Copy + TypeFoldable < ' tcx > + ' a >
573
- EarlyBinder < T >
601
+ impl < ' tcx , ' s , I : IntoIterator > EarlyBinder < I >
602
+ where
603
+ I :: Item : Deref ,
604
+ <I :: Item as Deref >:: Target : Copy + TypeFoldable < ' tcx > ,
574
605
{
575
606
pub fn subst_iter_copied (
576
607
self ,
577
608
tcx : TyCtxt < ' tcx > ,
578
609
substs : & ' s [ GenericArg < ' tcx > ] ,
579
- ) -> impl Iterator < Item = I > + Captures < ' s > + Captures < ' tcx > + Captures < ' a > {
580
- self . 0 . into_iter ( ) . map ( move |t| EarlyBinder ( * t) . subst ( tcx, substs) )
610
+ ) -> SubstIterCopied < ' s , ' tcx , I > {
611
+ SubstIterCopied { it : self . 0 . into_iter ( ) , tcx, substs }
612
+ }
613
+ }
614
+
615
+ pub struct SubstIterCopied < ' a , ' tcx , I : IntoIterator > {
616
+ it : I :: IntoIter ,
617
+ tcx : TyCtxt < ' tcx > ,
618
+ substs : & ' a [ GenericArg < ' tcx > ] ,
619
+ }
620
+
621
+ impl < ' tcx , I : IntoIterator > Iterator for SubstIterCopied < ' _ , ' tcx , I >
622
+ where
623
+ I :: Item : Deref ,
624
+ <I :: Item as Deref >:: Target : Copy + TypeFoldable < ' tcx > ,
625
+ {
626
+ type Item = <I :: Item as Deref >:: Target ;
627
+
628
+ fn next ( & mut self ) -> Option < Self :: Item > {
629
+ Some ( EarlyBinder ( * self . it . next ( ) ?) . subst ( self . tcx , self . substs ) )
630
+ }
631
+ }
632
+
633
+ impl < ' tcx , I : IntoIterator > DoubleEndedIterator for SubstIterCopied < ' _ , ' tcx , I >
634
+ where
635
+ I :: IntoIter : DoubleEndedIterator ,
636
+ I :: Item : Deref ,
637
+ <I :: Item as Deref >:: Target : Copy + TypeFoldable < ' tcx > ,
638
+ {
639
+ fn next_back ( & mut self ) -> Option < Self :: Item > {
640
+ Some ( EarlyBinder ( * self . it . next_back ( ) ?) . subst ( self . tcx , self . substs ) )
581
641
}
582
642
}
583
643
0 commit comments