11use std:: fmt;
22use std:: iter:: once;
3- use std:: ops:: ControlFlow ;
43
54use rustc_abi:: { FIRST_VARIANT , FieldIdx , Integer , VariantIdx } ;
65use rustc_arena:: DroplessArena ;
@@ -12,8 +11,7 @@ use rustc_middle::mir::{self, Const};
1211use rustc_middle:: thir:: { self , Pat , PatKind , PatRange , PatRangeBoundary } ;
1312use rustc_middle:: ty:: layout:: IntegerExt ;
1413use rustc_middle:: ty:: {
15- self , FieldDef , OpaqueTypeKey , ScalarInt , Ty , TyCtxt , TypeSuperVisitable , TypeVisitable ,
16- TypeVisitableExt , TypeVisitor , VariantDef ,
14+ self , FieldDef , OpaqueTypeKey , ScalarInt , Ty , TyCtxt , TypeVisitableExt , VariantDef ,
1715} ;
1816use rustc_middle:: { bug, span_bug} ;
1917use rustc_session:: lint;
@@ -137,22 +135,11 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
137135 /// Returns the hidden type corresponding to this key if the body under analysis is allowed to
138136 /// know it.
139137 fn reveal_opaque_key ( & self , key : OpaqueTypeKey < ' tcx > ) -> Option < Ty < ' tcx > > {
140- if let Some ( hidden_ty) = self . typeck_results . concrete_opaque_types . get ( & key. def_id ) {
141- let ty = ty:: EarlyBinder :: bind ( hidden_ty. ty ) . instantiate ( self . tcx , key. args ) ;
142- if ty. visit_with ( & mut RecursiveOpaque { def_id : key. def_id . into ( ) } ) . is_continue ( ) {
143- Some ( ty)
144- } else {
145- // HACK: We skip revealing opaque types which recursively expand
146- // to themselves. This is because we may infer hidden types like
147- // `Opaque<T> = Opaque<Opaque<T>>` or `Opaque<T> = Opaque<(T,)>`
148- // in hir typeck.
149- None
150- }
151- } else {
152- None
153- }
138+ self . typeck_results
139+ . concrete_opaque_types
140+ . get ( & key. def_id )
141+ . map ( |x| ty:: EarlyBinder :: bind ( x. ty ) . instantiate ( self . tcx , key. args ) )
154142 }
155-
156143 // This can take a non-revealed `Ty` because it reveals opaques itself.
157144 pub fn is_uninhabited ( & self , ty : Ty < ' tcx > ) -> bool {
158145 !ty. inhabited_predicate ( self . tcx ) . apply_revealing_opaque (
@@ -1118,20 +1105,3 @@ pub fn analyze_match<'p, 'tcx>(
11181105
11191106 Ok ( report)
11201107}
1121-
1122- struct RecursiveOpaque {
1123- def_id : DefId ,
1124- }
1125- impl < ' tcx > TypeVisitor < TyCtxt < ' tcx > > for RecursiveOpaque {
1126- type Result = ControlFlow < ( ) > ;
1127-
1128- fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> Self :: Result {
1129- if let ty:: Alias ( ty:: Opaque , alias_ty) = t. kind ( ) {
1130- if alias_ty. def_id == self . def_id {
1131- return ControlFlow :: Break ( ( ) ) ;
1132- }
1133- }
1134-
1135- if t. has_opaque_types ( ) { t. super_visit_with ( self ) } else { ControlFlow :: Continue ( ( ) ) }
1136- }
1137- }
0 commit comments