@@ -7,7 +7,9 @@ use rustc_hir::{HirId, Node};
7
7
use rustc_middle:: hir:: nested_filter;
8
8
use rustc_middle:: ty:: subst:: InternalSubsts ;
9
9
use 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
+ } ;
11
13
use rustc_span:: symbol:: Ident ;
12
14
use rustc_span:: { Span , DUMMY_SP } ;
13
15
@@ -538,6 +540,35 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
538
540
}
539
541
}
540
542
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
+
541
572
#[ instrument( skip( tcx) , level = "debug" ) ]
542
573
/// Checks "defining uses" of opaque `impl Trait` types to ensure that they meet the restrictions
543
574
/// laid for "higher-order pattern unification".
0 commit comments