@@ -50,15 +50,24 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
5050 }
5151
5252 fn parent ( & self ) -> Option < LocalDefId > {
53- match self . tcx . def_kind ( self . item ) {
53+ let mut item = self . item ;
54+ let mut kind;
55+ loop {
56+ kind = self . tcx . def_kind ( item) ;
57+ match kind {
58+ DefKind :: OpaqueTy => item = self . tcx . local_parent ( item) ,
59+ DefKind :: TyAlias => return None ,
60+ _ => break ,
61+ }
62+ }
63+ match kind {
5464 DefKind :: Fn => None ,
5565 DefKind :: AssocFn | DefKind :: AssocTy | DefKind :: AssocConst => {
56- Some ( self . tcx . local_parent ( self . item ) )
66+ Some ( self . tcx . local_parent ( item) )
67+ }
68+ other => {
69+ span_bug ! ( self . tcx. def_span( item) , "unhandled item with opaque types: {other:?}" )
5770 }
58- other => span_bug ! (
59- self . tcx. def_span( self . item) ,
60- "unhandled item with opaque types: {other:?}"
61- ) ,
6271 }
6372 }
6473}
@@ -216,6 +225,18 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
216225 }
217226 tcx. arena . alloc_from_iter ( collector. opaques )
218227 }
228+ DefKind :: OpaqueTy => {
229+ let mut collector = OpaqueTypeCollector :: new ( tcx, item) ;
230+ let span = match tcx. hir ( ) . get_by_def_id ( item) . ty ( ) {
231+ Some ( ty) => ty. span ,
232+ _ => tcx. def_span ( item) ,
233+ } ;
234+ collector. visit_spanned (
235+ span,
236+ tcx. mk_opaque ( item. to_def_id ( ) , ty:: InternalSubsts :: identity_for_item ( tcx, item) ) ,
237+ ) ;
238+ tcx. arena . alloc_from_iter ( collector. opaques )
239+ }
219240 DefKind :: Mod
220241 | DefKind :: Struct
221242 | DefKind :: Union
@@ -236,7 +257,6 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
236257 | DefKind :: ForeignMod
237258 | DefKind :: AnonConst
238259 | DefKind :: InlineConst
239- | DefKind :: OpaqueTy
240260 | DefKind :: ImplTraitPlaceholder
241261 | DefKind :: Field
242262 | DefKind :: LifetimeParam
0 commit comments