@@ -776,7 +776,6 @@ impl<'tcx> TyCtxt<'tcx> {
776776 self ,
777777 def_id : DefId ,
778778 args : GenericArgsRef < ' tcx > ,
779- inspect_coroutine_fields : InspectCoroutineFields ,
780779 ) -> Result < Ty < ' tcx > , Ty < ' tcx > > {
781780 let mut visitor = OpaqueTypeExpander {
782781 seen_opaque_tys : FxHashSet :: default ( ) ,
@@ -785,9 +784,7 @@ impl<'tcx> TyCtxt<'tcx> {
785784 found_recursion : false ,
786785 found_any_recursion : false ,
787786 check_recursion : true ,
788- expand_coroutines : true ,
789787 tcx : self ,
790- inspect_coroutine_fields,
791788 } ;
792789
793790 let expanded_type = visitor. expand_opaque_ty ( def_id, args) . unwrap ( ) ;
@@ -964,19 +961,11 @@ struct OpaqueTypeExpander<'tcx> {
964961 primary_def_id : Option < DefId > ,
965962 found_recursion : bool ,
966963 found_any_recursion : bool ,
967- expand_coroutines : bool ,
968964 /// Whether or not to check for recursive opaque types.
969965 /// This is `true` when we're explicitly checking for opaque type
970966 /// recursion, and 'false' otherwise to avoid unnecessary work.
971967 check_recursion : bool ,
972968 tcx : TyCtxt < ' tcx > ,
973- inspect_coroutine_fields : InspectCoroutineFields ,
974- }
975-
976- #[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
977- pub enum InspectCoroutineFields {
978- No ,
979- Yes ,
980969}
981970
982971impl < ' tcx > OpaqueTypeExpander < ' tcx > {
@@ -1008,41 +997,6 @@ impl<'tcx> OpaqueTypeExpander<'tcx> {
1008997 None
1009998 }
1010999 }
1011-
1012- fn expand_coroutine ( & mut self , def_id : DefId , args : GenericArgsRef < ' tcx > ) -> Option < Ty < ' tcx > > {
1013- if self . found_any_recursion {
1014- return None ;
1015- }
1016- let args = args. fold_with ( self ) ;
1017- if !self . check_recursion || self . seen_opaque_tys . insert ( def_id) {
1018- let expanded_ty = match self . expanded_cache . get ( & ( def_id, args) ) {
1019- Some ( expanded_ty) => * expanded_ty,
1020- None => {
1021- if matches ! ( self . inspect_coroutine_fields, InspectCoroutineFields :: Yes ) {
1022- for bty in self . tcx . bound_coroutine_hidden_types ( def_id) {
1023- let hidden_ty = self . tcx . instantiate_bound_regions_with_erased (
1024- bty. instantiate ( self . tcx , args) ,
1025- ) ;
1026- self . fold_ty ( hidden_ty) ;
1027- }
1028- }
1029- let expanded_ty = Ty :: new_coroutine_witness ( self . tcx , def_id, args) ;
1030- self . expanded_cache . insert ( ( def_id, args) , expanded_ty) ;
1031- expanded_ty
1032- }
1033- } ;
1034- if self . check_recursion {
1035- self . seen_opaque_tys . remove ( & def_id) ;
1036- }
1037- Some ( expanded_ty)
1038- } else {
1039- // If another opaque type that we contain is recursive, then it
1040- // will report the error, so we don't have to.
1041- self . found_any_recursion = true ;
1042- self . found_recursion = def_id == * self . primary_def_id . as_ref ( ) . unwrap ( ) ;
1043- None
1044- }
1045- }
10461000}
10471001
10481002impl < ' tcx > TypeFolder < TyCtxt < ' tcx > > for OpaqueTypeExpander < ' tcx > {
@@ -1051,19 +1005,13 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for OpaqueTypeExpander<'tcx> {
10511005 }
10521006
10531007 fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
1054- let mut t = if let ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, args, .. } ) = * t. kind ( ) {
1008+ if let ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, args, .. } ) = * t. kind ( ) {
10551009 self . expand_opaque_ty ( def_id, args) . unwrap_or ( t)
1056- } else if t. has_opaque_types ( ) || t . has_coroutines ( ) {
1010+ } else if t. has_opaque_types ( ) {
10571011 t. super_fold_with ( self )
10581012 } else {
10591013 t
1060- } ;
1061- if self . expand_coroutines {
1062- if let ty:: CoroutineWitness ( def_id, args) = * t. kind ( ) {
1063- t = self . expand_coroutine ( def_id, args) . unwrap_or ( t) ;
1064- }
10651014 }
1066- t
10671015 }
10681016
10691017 fn fold_predicate ( & mut self , p : ty:: Predicate < ' tcx > ) -> ty:: Predicate < ' tcx > {
@@ -1752,9 +1700,7 @@ pub fn reveal_opaque_types_in_bounds<'tcx>(
17521700 found_recursion : false ,
17531701 found_any_recursion : false ,
17541702 check_recursion : false ,
1755- expand_coroutines : false ,
17561703 tcx,
1757- inspect_coroutine_fields : InspectCoroutineFields :: No ,
17581704 } ;
17591705 val. fold_with ( & mut visitor)
17601706}
0 commit comments