@@ -701,22 +701,6 @@ impl<'tcx> TyCtxt<'tcx> {
701701 . map ( |decl| ty:: EarlyBinder :: bind ( decl. ty ) )
702702 }
703703
704- /// Normalizes all opaque types in the given value, replacing them
705- /// with their underlying types.
706- pub fn expand_opaque_types ( self , val : Ty < ' tcx > ) -> Ty < ' tcx > {
707- let mut visitor = OpaqueTypeExpander {
708- seen_opaque_tys : FxHashSet :: default ( ) ,
709- expanded_cache : FxHashMap :: default ( ) ,
710- primary_def_id : None ,
711- found_recursion : false ,
712- found_any_recursion : false ,
713- check_recursion : false ,
714- expand_coroutines : false ,
715- tcx : self ,
716- } ;
717- val. fold_with ( & mut visitor)
718- }
719-
720704 /// Expands the given impl trait type, stopping if the type is recursive.
721705 #[ instrument( skip( self ) , level = "debug" , ret) ]
722706 pub fn try_expand_impl_trait_type (
@@ -731,7 +715,6 @@ impl<'tcx> TyCtxt<'tcx> {
731715 found_recursion : false ,
732716 found_any_recursion : false ,
733717 check_recursion : true ,
734- expand_coroutines : true ,
735718 tcx : self ,
736719 } ;
737720
@@ -749,9 +732,13 @@ impl<'tcx> TyCtxt<'tcx> {
749732 match def_kind {
750733 DefKind :: AssocFn if self . associated_item ( def_id) . fn_has_self_parameter => "method" ,
751734 DefKind :: Coroutine => match self . coroutine_kind ( def_id) . unwrap ( ) {
752- rustc_hir:: CoroutineKind :: Async ( ..) => "async closure" ,
753- rustc_hir:: CoroutineKind :: Coroutine => "coroutine" ,
754- rustc_hir:: CoroutineKind :: Gen ( ..) => "gen closure" ,
735+ hir:: CoroutineKind :: Async ( hir:: CoroutineSource :: Fn ) => "async fn" ,
736+ hir:: CoroutineKind :: Async ( hir:: CoroutineSource :: Block ) => "async block" ,
737+ hir:: CoroutineKind :: Async ( hir:: CoroutineSource :: Closure ) => "async closure" ,
738+ hir:: CoroutineKind :: Gen ( hir:: CoroutineSource :: Fn ) => "gen fn" ,
739+ hir:: CoroutineKind :: Gen ( hir:: CoroutineSource :: Block ) => "gen block" ,
740+ hir:: CoroutineKind :: Gen ( hir:: CoroutineSource :: Closure ) => "gen closure" ,
741+ hir:: CoroutineKind :: Coroutine => "coroutine" ,
755742 } ,
756743 _ => def_kind. descr ( def_id) ,
757744 }
@@ -767,9 +754,9 @@ impl<'tcx> TyCtxt<'tcx> {
767754 match def_kind {
768755 DefKind :: AssocFn if self . associated_item ( def_id) . fn_has_self_parameter => "a" ,
769756 DefKind :: Coroutine => match self . coroutine_kind ( def_id) . unwrap ( ) {
770- rustc_hir :: CoroutineKind :: Async ( ..) => "an" ,
771- rustc_hir :: CoroutineKind :: Coroutine => "a" ,
772- rustc_hir :: CoroutineKind :: Gen ( ..) => "a" ,
757+ hir :: CoroutineKind :: Async ( ..) => "an" ,
758+ hir :: CoroutineKind :: Coroutine => "a" ,
759+ hir :: CoroutineKind :: Gen ( ..) => "a" ,
773760 } ,
774761 _ => def_kind. article ( ) ,
775762 }
@@ -808,7 +795,6 @@ struct OpaqueTypeExpander<'tcx> {
808795 primary_def_id : Option < DefId > ,
809796 found_recursion : bool ,
810797 found_any_recursion : bool ,
811- expand_coroutines : bool ,
812798 /// Whether or not to check for recursive opaque types.
813799 /// This is `true` when we're explicitly checking for opaque type
814800 /// recursion, and 'false' otherwise to avoid unnecessary work.
@@ -845,37 +831,6 @@ impl<'tcx> OpaqueTypeExpander<'tcx> {
845831 None
846832 }
847833 }
848-
849- fn expand_coroutine ( & mut self , def_id : DefId , args : GenericArgsRef < ' tcx > ) -> Option < Ty < ' tcx > > {
850- if self . found_any_recursion {
851- return None ;
852- }
853- let args = args. fold_with ( self ) ;
854- if !self . check_recursion || self . seen_opaque_tys . insert ( def_id) {
855- let expanded_ty = match self . expanded_cache . get ( & ( def_id, args) ) {
856- Some ( expanded_ty) => * expanded_ty,
857- None => {
858- for bty in self . tcx . coroutine_hidden_types ( def_id) {
859- let hidden_ty = bty. instantiate ( self . tcx , args) ;
860- self . fold_ty ( hidden_ty) ;
861- }
862- let expanded_ty = Ty :: new_coroutine_witness ( self . tcx , def_id, args) ;
863- self . expanded_cache . insert ( ( def_id, args) , expanded_ty) ;
864- expanded_ty
865- }
866- } ;
867- if self . check_recursion {
868- self . seen_opaque_tys . remove ( & def_id) ;
869- }
870- Some ( expanded_ty)
871- } else {
872- // If another opaque type that we contain is recursive, then it
873- // will report the error, so we don't have to.
874- self . found_any_recursion = true ;
875- self . found_recursion = def_id == * self . primary_def_id . as_ref ( ) . unwrap ( ) ;
876- None
877- }
878- }
879834}
880835
881836impl < ' tcx > TypeFolder < TyCtxt < ' tcx > > for OpaqueTypeExpander < ' tcx > {
@@ -884,22 +839,20 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for OpaqueTypeExpander<'tcx> {
884839 }
885840
886841 fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
887- let mut t = if let ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, args, .. } ) = * t. kind ( ) {
842+ if let ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, args, .. } ) = * t. kind ( ) {
888843 self . expand_opaque_ty ( def_id, args) . unwrap_or ( t)
889- } else if t. has_opaque_types ( ) || t . has_coroutines ( ) {
844+ } else if t. has_opaque_types ( ) {
890845 t. super_fold_with ( self )
891846 } else {
892847 t
893- } ;
894- if self . expand_coroutines {
895- if let ty:: CoroutineWitness ( def_id, args) = * t. kind ( ) {
896- t = self . expand_coroutine ( def_id, args) . unwrap_or ( t) ;
897- }
898848 }
899- t
900849 }
901850
902851 fn fold_predicate ( & mut self , p : ty:: Predicate < ' tcx > ) -> ty:: Predicate < ' tcx > {
852+ if !p. has_opaque_types ( ) {
853+ return p;
854+ }
855+
903856 if let ty:: PredicateKind :: Clause ( clause) = p. kind ( ) . skip_binder ( )
904857 && let ty:: ClauseKind :: Projection ( projection_pred) = clause
905858 {
@@ -1433,7 +1386,6 @@ pub fn reveal_opaque_types_in_bounds<'tcx>(
14331386 found_recursion : false ,
14341387 found_any_recursion : false ,
14351388 check_recursion : false ,
1436- expand_coroutines : false ,
14371389 tcx,
14381390 } ;
14391391 val. fold_with ( & mut visitor)
0 commit comments