@@ -20,6 +20,7 @@ use middle::subst;
20
20
use middle:: ty:: { self , HasProjectionTypes , Ty } ;
21
21
use middle:: ty_fold:: TypeFoldable ;
22
22
use middle:: infer:: { self , fixup_err_to_string, InferCtxt } ;
23
+ use std:: slice:: Iter ;
23
24
use std:: rc:: Rc ;
24
25
use syntax:: ast;
25
26
use syntax:: codemap:: { Span , DUMMY_SP } ;
@@ -145,9 +146,9 @@ pub struct DerivedObligationCause<'tcx> {
145
146
parent_code : Rc < ObligationCauseCode < ' tcx > >
146
147
}
147
148
148
- pub type Obligations < ' tcx , O > = Vec < Obligation < ' tcx , O > > ;
149
- pub type PredicateObligations < ' tcx > = Vec < PredicateObligation < ' tcx > > ;
150
- pub type TraitObligations < ' tcx > = Vec < TraitObligation < ' tcx > > ;
149
+ pub type Obligations < ' tcx , O > = subst :: VecPerParamSpace < Obligation < ' tcx , O > > ;
150
+ pub type PredicateObligations < ' tcx > = subst :: VecPerParamSpace < PredicateObligation < ' tcx > > ;
151
+ pub type TraitObligations < ' tcx > = subst :: VecPerParamSpace < TraitObligation < ' tcx > > ;
151
152
152
153
pub type Selection < ' tcx > = Vtable < ' tcx , PredicateObligation < ' tcx > > ;
153
154
@@ -265,7 +266,7 @@ pub enum Vtable<'tcx, N> {
265
266
pub struct VtableImplData < ' tcx , N > {
266
267
pub impl_def_id : ast:: DefId ,
267
268
pub substs : subst:: Substs < ' tcx > ,
268
- pub nested : Vec < N >
269
+ pub nested : subst :: VecPerParamSpace < N >
269
270
}
270
271
271
272
#[ derive( Debug , Clone ) ]
@@ -276,7 +277,7 @@ pub struct VtableDefaultImplData<N> {
276
277
277
278
#[ derive( Debug , Clone ) ]
278
279
pub struct VtableBuiltinData < N > {
279
- pub nested : Vec < N >
280
+ pub nested : subst :: VecPerParamSpace < N >
280
281
}
281
282
282
283
/// A vtable for some object-safe trait `Foo` automatically derived
@@ -524,35 +525,114 @@ impl<'tcx> ObligationCause<'tcx> {
524
525
}
525
526
526
527
impl < ' tcx , N > Vtable < ' tcx , N > {
527
- pub fn nested_obligations ( self ) -> Vec < N > {
528
- match self {
529
- VtableImpl ( i) => i. nested ,
530
- VtableParam ( n) => n,
531
- VtableBuiltin ( i) => i. nested ,
532
- VtableDefaultImpl ( d) => d. nested ,
533
- VtableObject ( _) | VtableFnPointer ( ..) |
534
- VtableClosure ( ..) => vec ! [ ]
528
+ pub fn iter_nested ( & self ) -> Iter < N > {
529
+ match * self {
530
+ VtableImpl ( ref i) => i. iter_nested ( ) ,
531
+ VtableParam ( ref n) => n. iter ( ) ,
532
+ VtableBuiltin ( ref i) => i. iter_nested ( ) ,
533
+ VtableObject ( _) |
534
+ VtableDefaultImpl ( ..) | VtableFnPointer ( ..) |
535
+ VtableClosure ( ..) => ( & [ ] ) . iter ( ) ,
536
+ }
537
+ }
538
+
539
+ pub fn map_nested < M , F > ( & self , op : F ) -> Vtable < ' tcx , M > where
540
+ F : FnMut ( & N ) -> M ,
541
+ {
542
+ match * self {
543
+ VtableImpl ( ref i) => VtableImpl ( i. map_nested ( op) ) ,
544
+ VtableDefaultImpl ( ref t) => VtableDefaultImpl ( t. map_nested ( op) ) ,
545
+ VtableFnPointer ( ref sig) => VtableFnPointer ( ( * sig) . clone ( ) ) ,
546
+ VtableClosure ( d, ref s) => VtableClosure ( d, s. clone ( ) ) ,
547
+ VtableParam ( ref n) => VtableParam ( n. iter ( ) . map ( op) . collect ( ) ) ,
548
+ VtableObject ( ref p) => VtableObject ( p. clone ( ) ) ,
549
+ VtableBuiltin ( ref b) => VtableBuiltin ( b. map_nested ( op) ) ,
535
550
}
536
551
}
537
552
538
- pub fn map < M , F > ( self , f : F ) -> Vtable < ' tcx , M > where F : FnMut ( N ) -> M {
553
+ pub fn map_move_nested < M , F > ( self , op : F ) -> Vtable < ' tcx , M > where
554
+ F : FnMut ( N ) -> M ,
555
+ {
539
556
match self {
540
- VtableImpl ( i) => VtableImpl ( VtableImplData {
541
- impl_def_id : i. impl_def_id ,
542
- substs : i. substs ,
543
- nested : i. nested . into_iter ( ) . map ( f) . collect ( )
544
- } ) ,
545
- VtableParam ( n) => VtableParam ( n. into_iter ( ) . map ( f) . collect ( ) ) ,
546
- VtableBuiltin ( i) => VtableBuiltin ( VtableBuiltinData {
547
- nested : i. nested . into_iter ( ) . map ( f) . collect ( )
548
- } ) ,
549
- VtableObject ( o) => VtableObject ( o) ,
550
- VtableDefaultImpl ( d) => VtableDefaultImpl ( VtableDefaultImplData {
551
- trait_def_id : d. trait_def_id ,
552
- nested : d. nested . into_iter ( ) . map ( f) . collect ( )
553
- } ) ,
554
- VtableFnPointer ( f) => VtableFnPointer ( f) ,
557
+ VtableImpl ( i) => VtableImpl ( i. map_move_nested ( op) ) ,
558
+ VtableFnPointer ( sig) => VtableFnPointer ( sig) ,
555
559
VtableClosure ( d, s) => VtableClosure ( d, s) ,
560
+ VtableDefaultImpl ( t) => VtableDefaultImpl ( t. map_move_nested ( op) ) ,
561
+ VtableParam ( n) => VtableParam ( n. into_iter ( ) . map ( op) . collect ( ) ) ,
562
+ VtableObject ( p) => VtableObject ( p) ,
563
+ VtableBuiltin ( no) => VtableBuiltin ( no. map_move_nested ( op) ) ,
564
+ }
565
+ }
566
+ }
567
+
568
+ impl < ' tcx , N > VtableImplData < ' tcx , N > {
569
+ pub fn iter_nested ( & self ) -> Iter < N > {
570
+ self . nested . iter ( )
571
+ }
572
+
573
+ pub fn map_nested < M , F > ( & self , op : F ) -> VtableImplData < ' tcx , M > where
574
+ F : FnMut ( & N ) -> M ,
575
+ {
576
+ VtableImplData {
577
+ impl_def_id : self . impl_def_id ,
578
+ substs : self . substs . clone ( ) ,
579
+ nested : self . nested . map ( op)
580
+ }
581
+ }
582
+
583
+ pub fn map_move_nested < M , F > ( self , op : F ) -> VtableImplData < ' tcx , M > where
584
+ F : FnMut ( N ) -> M ,
585
+ {
586
+ let VtableImplData { impl_def_id, substs, nested } = self ;
587
+ VtableImplData {
588
+ impl_def_id : impl_def_id,
589
+ substs : substs,
590
+ nested : nested. map_move ( op)
591
+ }
592
+ }
593
+ }
594
+
595
+ impl < N > VtableDefaultImplData < N > {
596
+ pub fn iter_nested ( & self ) -> Iter < N > {
597
+ self . nested . iter ( )
598
+ }
599
+
600
+ pub fn map_nested < M , F > ( & self , op : F ) -> VtableDefaultImplData < M > where
601
+ F : FnMut ( & N ) -> M ,
602
+ {
603
+ VtableDefaultImplData {
604
+ trait_def_id : self . trait_def_id ,
605
+ nested : self . nested . iter ( ) . map ( op) . collect ( )
606
+ }
607
+ }
608
+
609
+ pub fn map_move_nested < M , F > ( self , op : F ) -> VtableDefaultImplData < M > where
610
+ F : FnMut ( N ) -> M ,
611
+ {
612
+ let VtableDefaultImplData { trait_def_id, nested } = self ;
613
+ VtableDefaultImplData {
614
+ trait_def_id : trait_def_id,
615
+ nested : nested. into_iter ( ) . map ( op) . collect ( )
616
+ }
617
+ }
618
+ }
619
+
620
+ impl < N > VtableBuiltinData < N > {
621
+ pub fn iter_nested ( & self ) -> Iter < N > {
622
+ self . nested . iter ( )
623
+ }
624
+
625
+ pub fn map_nested < M , F > ( & self , op : F ) -> VtableBuiltinData < M > where F : FnMut ( & N ) -> M {
626
+ VtableBuiltinData {
627
+ nested : self . nested . map ( op)
628
+ }
629
+ }
630
+
631
+ pub fn map_move_nested < M , F > ( self , op : F ) -> VtableBuiltinData < M > where
632
+ F : FnMut ( N ) -> M ,
633
+ {
634
+ VtableBuiltinData {
635
+ nested : self . nested . map_move ( op)
556
636
}
557
637
}
558
638
}
0 commit comments