@@ -50,15 +50,24 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
50
50
}
51
51
52
52
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 {
54
64
DefKind :: Fn => None ,
55
65
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:?}" )
57
70
}
58
- other => span_bug ! (
59
- self . tcx. def_span( self . item) ,
60
- "unhandled item with opaque types: {other:?}"
61
- ) ,
62
71
}
63
72
}
64
73
}
@@ -216,6 +225,18 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
216
225
}
217
226
tcx. arena . alloc_from_iter ( collector. opaques )
218
227
}
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
+ }
219
240
DefKind :: Mod
220
241
| DefKind :: Struct
221
242
| DefKind :: Union
@@ -236,7 +257,6 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
236
257
| DefKind :: ForeignMod
237
258
| DefKind :: AnonConst
238
259
| DefKind :: InlineConst
239
- | DefKind :: OpaqueTy
240
260
| DefKind :: ImplTraitPlaceholder
241
261
| DefKind :: Field
242
262
| DefKind :: LifetimeParam
0 commit comments