1
1
use rustc_data_structures:: fx:: FxHashMap ;
2
2
use rustc_hir:: { def_id:: DefId , Movability , Mutability } ;
3
3
use rustc_infer:: traits:: query:: NoSolution ;
4
- use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeFoldable , TypeFolder , TypeSuperFoldable } ;
4
+ use rustc_middle:: ty:: {
5
+ self , Ty , TyCtxt , TypeFoldable , TypeFolder , TypeSuperFoldable , TypeVisitableExt ,
6
+ } ;
5
7
6
8
use crate :: solve:: EvalCtxt ;
7
9
@@ -60,7 +62,16 @@ pub(super) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
60
62
61
63
ty:: GeneratorWitness ( types) => Ok ( ecx. instantiate_binder_with_placeholders ( types) . to_vec ( ) ) ,
62
64
63
- ty:: GeneratorWitnessMIR ( ..) => todo ! ( ) ,
65
+ ty:: GeneratorWitnessMIR ( def_id, substs) => Ok ( ecx
66
+ . tcx ( )
67
+ . generator_hidden_types ( def_id)
68
+ . map ( |bty| {
69
+ ecx. instantiate_binder_with_placeholders ( replace_erased_lifetimes_with_bound_vars (
70
+ tcx,
71
+ bty. subst ( tcx, substs) ,
72
+ ) )
73
+ } )
74
+ . collect ( ) ) ,
64
75
65
76
// For `PhantomData<T>`, we pass `T`.
66
77
ty:: Adt ( def, substs) if def. is_phantom_data ( ) => Ok ( vec ! [ substs. type_at( 0 ) ] ) ,
@@ -76,6 +87,29 @@ pub(super) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
76
87
}
77
88
}
78
89
90
+ fn replace_erased_lifetimes_with_bound_vars < ' tcx > (
91
+ tcx : TyCtxt < ' tcx > ,
92
+ ty : Ty < ' tcx > ,
93
+ ) -> ty:: Binder < ' tcx , Ty < ' tcx > > {
94
+ debug_assert ! ( !ty. has_late_bound_regions( ) ) ;
95
+ let mut counter = 0 ;
96
+ let ty = tcx. fold_regions ( ty, |mut r, current_depth| {
97
+ if let ty:: ReErased = r. kind ( ) {
98
+ let br = ty:: BoundRegion {
99
+ var : ty:: BoundVar :: from_u32 ( counter) ,
100
+ kind : ty:: BrAnon ( counter, None ) ,
101
+ } ;
102
+ counter += 1 ;
103
+ r = tcx. mk_re_late_bound ( current_depth, br) ;
104
+ }
105
+ r
106
+ } ) ;
107
+ let bound_vars = tcx. mk_bound_variable_kinds_from_iter (
108
+ ( 0 ..counter) . map ( |i| ty:: BoundVariableKind :: Region ( ty:: BrAnon ( i, None ) ) ) ,
109
+ ) ;
110
+ ty:: Binder :: bind_with_vars ( ty, bound_vars)
111
+ }
112
+
79
113
pub ( super ) fn instantiate_constituent_tys_for_sized_trait < ' tcx > (
80
114
ecx : & EvalCtxt < ' _ , ' tcx > ,
81
115
ty : Ty < ' tcx > ,
@@ -178,7 +212,16 @@ pub(super) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
178
212
179
213
ty:: GeneratorWitness ( types) => Ok ( ecx. instantiate_binder_with_placeholders ( types) . to_vec ( ) ) ,
180
214
181
- ty:: GeneratorWitnessMIR ( ..) => todo ! ( ) ,
215
+ ty:: GeneratorWitnessMIR ( def_id, substs) => Ok ( ecx
216
+ . tcx ( )
217
+ . generator_hidden_types ( def_id)
218
+ . map ( |bty| {
219
+ ecx. instantiate_binder_with_placeholders ( replace_erased_lifetimes_with_bound_vars (
220
+ ecx. tcx ( ) ,
221
+ bty. subst ( ecx. tcx ( ) , substs) ,
222
+ ) )
223
+ } )
224
+ . collect ( ) ) ,
182
225
}
183
226
}
184
227
0 commit comments