@@ -7,7 +7,9 @@ use rustc_hir::{HirId, Node};
77use rustc_middle:: hir:: nested_filter;
88use rustc_middle:: ty:: subst:: InternalSubsts ;
99use rustc_middle:: ty:: util:: IntTypeExt ;
10- use rustc_middle:: ty:: { self , DefIdTree , Ty , TyCtxt , TypeFolder , TypeSuperFoldable , TypeVisitable } ;
10+ use rustc_middle:: ty:: {
11+ self , DefIdTree , Ty , TyCtxt , TypeFoldable , TypeFolder , TypeSuperFoldable , TypeVisitable ,
12+ } ;
1113use rustc_span:: symbol:: Ident ;
1214use rustc_span:: { Span , DUMMY_SP } ;
1315
@@ -538,6 +540,35 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
538540 }
539541}
540542
543+ pub fn fully_revealed_type_of < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> Ty < ' tcx > {
544+ let ty = tcx. type_of ( def_id) ;
545+ if ty. has_opaque_types ( ) { ty. fold_with ( & mut DeeperTypeFolder { tcx } ) } else { ty }
546+ }
547+
548+ struct DeeperTypeFolder < ' tcx > {
549+ tcx : TyCtxt < ' tcx > ,
550+ }
551+
552+ impl < ' tcx > TypeFolder < ' tcx > for DeeperTypeFolder < ' tcx > {
553+ fn tcx ( & self ) -> TyCtxt < ' tcx > {
554+ self . tcx
555+ }
556+
557+ fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
558+ if !ty. has_opaque_types ( ) {
559+ return ty;
560+ }
561+
562+ let ty = ty. super_fold_with ( self ) ;
563+
564+ if let ty:: Opaque ( def_id, substs) = * ty. kind ( ) {
565+ self . tcx . bound_fully_revealed_type_of ( def_id) . subst ( self . tcx , substs)
566+ } else {
567+ ty
568+ }
569+ }
570+ }
571+
541572#[ instrument( skip( tcx) , level = "debug" ) ]
542573/// Checks "defining uses" of opaque `impl Trait` types to ensure that they meet the restrictions
543574/// laid for "higher-order pattern unification".
0 commit comments