@@ -777,7 +777,6 @@ impl<'tcx> TyCtxt<'tcx> {
777777 self ,
778778 def_id : DefId ,
779779 args : GenericArgsRef < ' tcx > ,
780- inspect_coroutine_fields : InspectCoroutineFields ,
781780 ) -> Result < Ty < ' tcx > , Ty < ' tcx > > {
782781 let mut visitor = OpaqueTypeExpander {
783782 seen_opaque_tys : FxHashSet :: default ( ) ,
@@ -786,9 +785,7 @@ impl<'tcx> TyCtxt<'tcx> {
786785 found_recursion : false ,
787786 found_any_recursion : false ,
788787 check_recursion : true ,
789- expand_coroutines : true ,
790788 tcx : self ,
791- inspect_coroutine_fields,
792789 } ;
793790
794791 let expanded_type = visitor. expand_opaque_ty ( def_id, args) . unwrap ( ) ;
@@ -965,19 +962,11 @@ struct OpaqueTypeExpander<'tcx> {
965962 primary_def_id : Option < DefId > ,
966963 found_recursion : bool ,
967964 found_any_recursion : bool ,
968- expand_coroutines : bool ,
969965 /// Whether or not to check for recursive opaque types.
970966 /// This is `true` when we're explicitly checking for opaque type
971967 /// recursion, and 'false' otherwise to avoid unnecessary work.
972968 check_recursion : bool ,
973969 tcx : TyCtxt < ' tcx > ,
974- inspect_coroutine_fields : InspectCoroutineFields ,
975- }
976-
977- #[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
978- pub enum InspectCoroutineFields {
979- No ,
980- Yes ,
981970}
982971
983972impl < ' tcx > OpaqueTypeExpander < ' tcx > {
@@ -1009,41 +998,6 @@ impl<'tcx> OpaqueTypeExpander<'tcx> {
1009998 None
1010999 }
10111000 }
1012-
1013- fn expand_coroutine ( & mut self , def_id : DefId , args : GenericArgsRef < ' tcx > ) -> Option < Ty < ' tcx > > {
1014- if self . found_any_recursion {
1015- return None ;
1016- }
1017- let args = args. fold_with ( self ) ;
1018- if !self . check_recursion || self . seen_opaque_tys . insert ( def_id) {
1019- let expanded_ty = match self . expanded_cache . get ( & ( def_id, args) ) {
1020- Some ( expanded_ty) => * expanded_ty,
1021- None => {
1022- if matches ! ( self . inspect_coroutine_fields, InspectCoroutineFields :: Yes ) {
1023- for bty in self . tcx . bound_coroutine_hidden_types ( def_id) {
1024- let hidden_ty = self . tcx . instantiate_bound_regions_with_erased (
1025- bty. instantiate ( self . tcx , args) ,
1026- ) ;
1027- self . fold_ty ( hidden_ty) ;
1028- }
1029- }
1030- let expanded_ty = Ty :: new_coroutine_witness ( self . tcx , def_id, args) ;
1031- self . expanded_cache . insert ( ( def_id, args) , expanded_ty) ;
1032- expanded_ty
1033- }
1034- } ;
1035- if self . check_recursion {
1036- self . seen_opaque_tys . remove ( & def_id) ;
1037- }
1038- Some ( expanded_ty)
1039- } else {
1040- // If another opaque type that we contain is recursive, then it
1041- // will report the error, so we don't have to.
1042- self . found_any_recursion = true ;
1043- self . found_recursion = def_id == * self . primary_def_id . as_ref ( ) . unwrap ( ) ;
1044- None
1045- }
1046- }
10471001}
10481002
10491003impl < ' tcx > TypeFolder < TyCtxt < ' tcx > > for OpaqueTypeExpander < ' tcx > {
@@ -1052,19 +1006,13 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for OpaqueTypeExpander<'tcx> {
10521006 }
10531007
10541008 fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
1055- let mut t = if let ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, args, .. } ) = * t. kind ( ) {
1009+ if let ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, args, .. } ) = * t. kind ( ) {
10561010 self . expand_opaque_ty ( def_id, args) . unwrap_or ( t)
1057- } else if t. has_opaque_types ( ) || t . has_coroutines ( ) {
1011+ } else if t. has_opaque_types ( ) {
10581012 t. super_fold_with ( self )
10591013 } else {
10601014 t
1061- } ;
1062- if self . expand_coroutines {
1063- if let ty:: CoroutineWitness ( def_id, args) = * t. kind ( ) {
1064- t = self . expand_coroutine ( def_id, args) . unwrap_or ( t) ;
1065- }
10661015 }
1067- t
10681016 }
10691017
10701018 fn fold_predicate ( & mut self , p : ty:: Predicate < ' tcx > ) -> ty:: Predicate < ' tcx > {
@@ -1753,9 +1701,7 @@ pub fn reveal_opaque_types_in_bounds<'tcx>(
17531701 found_recursion : false ,
17541702 found_any_recursion : false ,
17551703 check_recursion : false ,
1756- expand_coroutines : false ,
17571704 tcx,
1758- inspect_coroutine_fields : InspectCoroutineFields :: No ,
17591705 } ;
17601706 val. fold_with ( & mut visitor)
17611707}
0 commit comments