@@ -239,73 +239,56 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
239
239
fn opaque_types_defined_by < ' tcx > ( tcx : TyCtxt < ' tcx > , item : LocalDefId ) -> & ' tcx [ LocalDefId ] {
240
240
let kind = tcx. def_kind ( item) ;
241
241
trace ! ( ?kind) ;
242
+ let mut collector = OpaqueTypeCollector :: new ( tcx, item) ;
242
243
match kind {
243
244
// We're also doing this for `AssocTy` for the wf checks in `check_opaque_meets_bounds`
244
245
DefKind :: Static ( _)
245
246
| DefKind :: Const
246
- | DefKind :: TyAlias
247
- | DefKind :: Fn
248
- | DefKind :: OpaqueTy
247
+ | DefKind :: AssocConst
248
+ | DefKind :: AssocFn
249
249
| DefKind :: AnonConst
250
250
| DefKind :: InlineConst
251
- | DefKind :: AssocFn
252
- | DefKind :: AssocTy
253
- | DefKind :: AssocConst => {
254
- let mut collector = OpaqueTypeCollector :: new ( tcx, item) ;
251
+ | DefKind :: Fn => {
255
252
match kind {
253
+ // Walk over the signature of the function-like to find the opaques.
254
+ DefKind :: AssocFn | DefKind :: Fn => {
255
+ let ty_sig = tcx. fn_sig ( item) . subst_identity ( ) ;
256
+ let hir_sig = tcx. hir ( ) . get_by_def_id ( item) . fn_sig ( ) . unwrap ( ) ;
257
+ // Walk over the inputs and outputs manually in order to get good spans for them.
258
+ collector. visit_spanned ( hir_sig. decl . output . span ( ) , ty_sig. output ( ) ) ;
259
+ for ( hir, ty) in hir_sig. decl . inputs . iter ( ) . zip ( ty_sig. inputs ( ) . iter ( ) ) {
260
+ collector. visit_spanned ( hir. span , ty. map_bound ( |x| * x) ) ;
261
+ }
262
+ }
263
+ // Walk over the type of the item to find opaques.
256
264
DefKind :: Static ( _)
257
265
| DefKind :: Const
258
266
| DefKind :: AssocConst
259
- | DefKind :: AssocFn
260
267
| DefKind :: AnonConst
261
- | DefKind :: InlineConst
262
- | DefKind :: Fn => {
263
- match kind {
264
- // Walk over the signature of the function-like to find the opaques.
265
- DefKind :: AssocFn | DefKind :: Fn => {
266
- let ty_sig = tcx. fn_sig ( item) . subst_identity ( ) ;
267
- let hir_sig = tcx. hir ( ) . get_by_def_id ( item) . fn_sig ( ) . unwrap ( ) ;
268
- // Walk over the inputs and outputs manually in order to get good spans for them.
269
- collector. visit_spanned ( hir_sig. decl . output . span ( ) , ty_sig. output ( ) ) ;
270
- for ( hir, ty) in hir_sig. decl . inputs . iter ( ) . zip ( ty_sig. inputs ( ) . iter ( ) )
271
- {
272
- collector. visit_spanned ( hir. span , ty. map_bound ( |x| * x) ) ;
273
- }
274
- }
275
- // Walk over the type of the item to find opaques.
276
- DefKind :: Static ( _)
277
- | DefKind :: Const
278
- | DefKind :: AssocConst
279
- | DefKind :: AnonConst
280
- | DefKind :: InlineConst => {
281
- let span = match tcx. hir ( ) . get_by_def_id ( item) . ty ( ) {
282
- Some ( ty) => ty. span ,
283
- _ => tcx. def_span ( item) ,
284
- } ;
285
- collector. visit_spanned ( span, tcx. type_of ( item) . subst_identity ( ) ) ;
286
- }
287
- _ => unreachable ! ( ) ,
288
- }
289
- // Look at all where bounds.
290
- tcx. predicates_of ( item) . instantiate_identity ( tcx) . visit_with ( & mut collector) ;
291
- // An item is allowed to constrain opaques declared within its own body (but not nested within
292
- // nested functions).
293
- for id in find_taits_declared_in_body ( tcx, item) {
294
- collector. opaques . extend ( tcx. opaque_types_defined_by ( id) )
295
- }
296
- }
297
- DefKind :: TyAlias | DefKind :: AssocTy => {
298
- tcx. type_of ( item) . subst_identity ( ) . visit_with ( & mut collector) ;
299
- }
300
- DefKind :: OpaqueTy => {
301
- for ( pred, span) in tcx. explicit_item_bounds ( item) . subst_identity_iter_copied ( )
302
- {
303
- collector. visit_spanned ( span, pred) ;
304
- }
268
+ | DefKind :: InlineConst => {
269
+ let span = match tcx. hir ( ) . get_by_def_id ( item) . ty ( ) {
270
+ Some ( ty) => ty. span ,
271
+ _ => tcx. def_span ( item) ,
272
+ } ;
273
+ collector. visit_spanned ( span, tcx. type_of ( item) . subst_identity ( ) ) ;
305
274
}
306
275
_ => unreachable ! ( ) ,
307
276
}
308
- tcx. arena . alloc_from_iter ( collector. opaques )
277
+ // Look at all where bounds.
278
+ tcx. predicates_of ( item) . instantiate_identity ( tcx) . visit_with ( & mut collector) ;
279
+ // An item is allowed to constrain opaques declared within its own body (but not nested within
280
+ // nested functions).
281
+ for id in find_taits_declared_in_body ( tcx, item) {
282
+ collector. opaques . extend ( tcx. opaque_types_defined_by ( id) )
283
+ }
284
+ }
285
+ DefKind :: TyAlias | DefKind :: AssocTy => {
286
+ tcx. type_of ( item) . subst_identity ( ) . visit_with ( & mut collector) ;
287
+ }
288
+ DefKind :: OpaqueTy => {
289
+ for ( pred, span) in tcx. explicit_item_bounds ( item) . subst_identity_iter_copied ( ) {
290
+ collector. visit_spanned ( span, pred) ;
291
+ }
309
292
}
310
293
DefKind :: Mod
311
294
| DefKind :: Struct
@@ -326,11 +309,12 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
326
309
| DefKind :: Field
327
310
| DefKind :: LifetimeParam
328
311
| DefKind :: GlobalAsm
329
- | DefKind :: Impl { .. } => & [ ] ,
312
+ | DefKind :: Impl { .. } => { }
330
313
DefKind :: Closure | DefKind :: Generator => {
331
- tcx. opaque_types_defined_by ( tcx. local_parent ( item) )
314
+ return tcx. opaque_types_defined_by ( tcx. local_parent ( item) ) ;
332
315
}
333
316
}
317
+ tcx. arena . alloc_from_iter ( collector. opaques )
334
318
}
335
319
336
320
#[ instrument( level = "trace" , skip( tcx) , ret) ]
0 commit comments