@@ -682,6 +682,9 @@ impl<'tcx> TyCtxt<'tcx> {
682
682
683
683
/// Return the set of types that should be taken into account when checking
684
684
/// trait bounds on a coroutine's internal state.
685
+ // FIXME(compiler-errors): We should remove this when the old solver goes away;
686
+ // and all other usages of this function should go through `bound_coroutine_hidden_types`
687
+ // instead.
685
688
pub fn coroutine_hidden_types (
686
689
self ,
687
690
def_id : DefId ,
@@ -694,6 +697,33 @@ impl<'tcx> TyCtxt<'tcx> {
694
697
. map ( |decl| ty:: EarlyBinder :: bind ( decl. ty ) )
695
698
}
696
699
700
+ /// Return the set of types that should be taken into account when checking
701
+ /// trait bounds on a coroutine's internal state. This properly replaces
702
+ /// `ReErased` with new existential bound lifetimes.
703
+ pub fn bound_coroutine_hidden_types (
704
+ self ,
705
+ def_id : DefId ,
706
+ ) -> impl Iterator < Item = ty:: EarlyBinder < ty:: Binder < ' tcx , Ty < ' tcx > > > > {
707
+ let coroutine_layout = self . mir_coroutine_witnesses ( def_id) ;
708
+ coroutine_layout
709
+ . as_ref ( )
710
+ . map_or_else ( || [ ] . iter ( ) , |l| l. field_tys . iter ( ) )
711
+ . filter ( |decl| !decl. ignore_for_traits )
712
+ . map ( move |decl| {
713
+ let mut vars = vec ! [ ] ;
714
+ let ty = self . fold_regions ( decl. ty , |re, debruijn| {
715
+ assert_eq ! ( re, self . lifetimes. re_erased) ;
716
+ let var = ty:: BoundVar :: from_usize ( vars. len ( ) ) ;
717
+ vars. push ( ty:: BoundVariableKind :: Region ( ty:: BrAnon ) ) ;
718
+ ty:: Region :: new_bound ( self , debruijn, ty:: BoundRegion { var, kind : ty:: BrAnon } )
719
+ } ) ;
720
+ ty:: EarlyBinder :: bind ( ty:: Binder :: bind_with_vars (
721
+ ty,
722
+ self . mk_bound_variable_kinds ( & vars) ,
723
+ ) )
724
+ } )
725
+ }
726
+
697
727
/// Expands the given impl trait type, stopping if the type is recursive.
698
728
#[ instrument( skip( self ) , level = "debug" , ret) ]
699
729
pub fn try_expand_impl_trait_type (
@@ -998,8 +1028,10 @@ impl<'tcx> OpaqueTypeExpander<'tcx> {
998
1028
Some ( expanded_ty) => * expanded_ty,
999
1029
None => {
1000
1030
if matches ! ( self . inspect_coroutine_fields, InspectCoroutineFields :: Yes ) {
1001
- for bty in self . tcx . coroutine_hidden_types ( def_id) {
1002
- let hidden_ty = bty. instantiate ( self . tcx , args) ;
1031
+ for bty in self . tcx . bound_coroutine_hidden_types ( def_id) {
1032
+ let hidden_ty = self . tcx . instantiate_bound_regions_with_erased (
1033
+ bty. instantiate ( self . tcx , args) ,
1034
+ ) ;
1003
1035
self . fold_ty ( hidden_ty) ;
1004
1036
}
1005
1037
}
0 commit comments