@@ -9,7 +9,7 @@ use std::ops::ControlFlow;
9
9
use std:: { cmp, iter} ;
10
10
11
11
use hir:: def:: DefKind ;
12
- use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
12
+ use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
13
13
use rustc_data_structures:: stack:: ensure_sufficient_stack;
14
14
use rustc_errors:: { Diag , EmissionGuarantee } ;
15
15
use rustc_hir as hir;
@@ -25,7 +25,6 @@ use rustc_middle::dep_graph::{DepNodeIndex, dep_kinds};
25
25
pub use rustc_middle:: traits:: select:: * ;
26
26
use rustc_middle:: ty:: abstract_const:: NotConstEvaluatable ;
27
27
use rustc_middle:: ty:: error:: TypeErrorToStringExt ;
28
- use rustc_middle:: ty:: fold:: fold_regions;
29
28
use rustc_middle:: ty:: print:: { PrintTraitRefExt as _, with_no_trimmed_paths} ;
30
29
use rustc_middle:: ty:: {
31
30
self , GenericArgsRef , PolyProjectionPredicate , Ty , TyCtxt , TypeFoldable , TypeVisitableExt ,
@@ -2199,8 +2198,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
2199
2198
}
2200
2199
2201
2200
ty:: CoroutineWitness ( def_id, args) => {
2202
- let hidden_types = bind_coroutine_hidden_types_above (
2203
- self . infcx ,
2201
+ let hidden_types = rebind_coroutine_witness_types (
2202
+ self . infcx . tcx ,
2204
2203
def_id,
2205
2204
args,
2206
2205
obligation. predicate . bound_vars ( ) ,
@@ -2348,7 +2347,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
2348
2347
}
2349
2348
2350
2349
ty:: CoroutineWitness ( def_id, args) => {
2351
- bind_coroutine_hidden_types_above ( self . infcx , def_id, args, t. bound_vars ( ) )
2350
+ rebind_coroutine_witness_types ( self . infcx . tcx , def_id, args, t. bound_vars ( ) )
2352
2351
}
2353
2352
2354
2353
// For `PhantomData<T>`, we pass `T`.
@@ -2843,6 +2842,23 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
2843
2842
}
2844
2843
}
2845
2844
2845
+ fn rebind_coroutine_witness_types < ' tcx > (
2846
+ tcx : TyCtxt < ' tcx > ,
2847
+ def_id : DefId ,
2848
+ args : ty:: GenericArgsRef < ' tcx > ,
2849
+ bound_vars : & ' tcx ty:: List < ty:: BoundVariableKind > ,
2850
+ ) -> ty:: Binder < ' tcx , Vec < Ty < ' tcx > > > {
2851
+ let bound_coroutine_types = tcx. coroutine_hidden_types ( def_id) . skip_binder ( ) ;
2852
+ let shifted_coroutine_types =
2853
+ tcx. shift_bound_var_indices ( bound_vars. len ( ) , bound_coroutine_types. skip_binder ( ) ) ;
2854
+ ty:: Binder :: bind_with_vars (
2855
+ ty:: EarlyBinder :: bind ( shifted_coroutine_types. to_vec ( ) ) . instantiate ( tcx, args) ,
2856
+ tcx. mk_bound_variable_kinds_from_iter (
2857
+ bound_vars. iter ( ) . chain ( bound_coroutine_types. bound_vars ( ) ) ,
2858
+ ) ,
2859
+ )
2860
+ }
2861
+
2846
2862
impl < ' o , ' tcx > TraitObligationStack < ' o , ' tcx > {
2847
2863
fn list ( & ' o self ) -> TraitObligationStackList < ' o , ' tcx > {
2848
2864
TraitObligationStackList :: with ( self )
@@ -3151,56 +3167,3 @@ pub(crate) enum ProjectionMatchesProjection {
3151
3167
Ambiguous ,
3152
3168
No ,
3153
3169
}
3154
-
3155
- /// Replace all regions inside the coroutine interior with late bound regions.
3156
- /// Note that each region slot in the types gets a new fresh late bound region, which means that
3157
- /// none of the regions inside relate to any other, even if typeck had previously found constraints
3158
- /// that would cause them to be related.
3159
- #[ instrument( level = "trace" , skip( infcx) , ret) ]
3160
- fn bind_coroutine_hidden_types_above < ' tcx > (
3161
- infcx : & InferCtxt < ' tcx > ,
3162
- def_id : DefId ,
3163
- args : ty:: GenericArgsRef < ' tcx > ,
3164
- bound_vars : & ty:: List < ty:: BoundVariableKind > ,
3165
- ) -> ty:: Binder < ' tcx , Vec < Ty < ' tcx > > > {
3166
- let tcx = infcx. tcx ;
3167
- let mut seen_tys = FxHashSet :: default ( ) ;
3168
-
3169
- let considering_regions = infcx. considering_regions ;
3170
-
3171
- let num_bound_variables = bound_vars. len ( ) as u32 ;
3172
- let mut counter = num_bound_variables;
3173
-
3174
- let hidden_types: Vec < _ > = tcx
3175
- . coroutine_hidden_types ( def_id)
3176
- // Deduplicate tys to avoid repeated work.
3177
- . filter ( |bty| seen_tys. insert ( * bty) )
3178
- . map ( |mut bty| {
3179
- // Only remap erased regions if we use them.
3180
- if considering_regions {
3181
- bty = bty. map_bound ( |ty| {
3182
- fold_regions ( tcx, ty, |r, current_depth| match r. kind ( ) {
3183
- ty:: ReErased => {
3184
- let br = ty:: BoundRegion {
3185
- var : ty:: BoundVar :: from_u32 ( counter) ,
3186
- kind : ty:: BoundRegionKind :: Anon ,
3187
- } ;
3188
- counter += 1 ;
3189
- ty:: Region :: new_bound ( tcx, current_depth, br)
3190
- }
3191
- r => bug ! ( "unexpected region: {r:?}" ) ,
3192
- } )
3193
- } )
3194
- }
3195
-
3196
- bty. instantiate ( tcx, args)
3197
- } )
3198
- . collect ( ) ;
3199
- let bound_vars = tcx. mk_bound_variable_kinds_from_iter (
3200
- bound_vars. iter ( ) . chain (
3201
- ( num_bound_variables..counter)
3202
- . map ( |_| ty:: BoundVariableKind :: Region ( ty:: BoundRegionKind :: Anon ) ) ,
3203
- ) ,
3204
- ) ;
3205
- ty:: Binder :: bind_with_vars ( hidden_types, bound_vars)
3206
- }
0 commit comments