@@ -121,6 +121,12 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
121
121
self.collector.opaques.extend(items);
122
122
}
123
123
}
124
+ #[instrument(level = "trace", skip(self))]
125
+ // Recurse into these, as they are type checked with their parent
126
+ fn visit_nested_body(&mut self, id: rustc_hir::BodyId) {
127
+ let body = self.collector.tcx.hir().body(id);
128
+ self.visit_body(body);
129
+ }
124
130
}
125
131
TaitInBodyFinder { collector: self }.visit_expr(body);
126
132
}
@@ -280,11 +286,7 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
280
286
collector.collect_body_and_predicate_taits();
281
287
}
282
288
// Walk over the type of the item to find opaques.
283
- DefKind::Static(_)
284
- | DefKind::Const
285
- | DefKind::AssocConst
286
- | DefKind::AnonConst
287
- | DefKind::InlineConst => {
289
+ DefKind::Static(_) | DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => {
288
290
let span = match tcx.hir().get_by_def_id(item).ty() {
289
291
Some(ty) => ty.span,
290
292
_ => tcx.def_span(item),
@@ -321,11 +323,9 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
321
323
| DefKind::LifetimeParam
322
324
| DefKind::GlobalAsm
323
325
| DefKind::Impl { .. } => {}
324
- DefKind::Closure | DefKind::Generator => {
325
- // All items in the signature of the parent are ok
326
- collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item)));
327
- // And items in the body of the closure itself
328
- collector.collect_taits_declared_in_body();
326
+ // Closures and generators are type checked with their parent, so there is no difference here.
327
+ DefKind::Closure | DefKind::Generator | DefKind::InlineConst => {
328
+ return tcx.opaque_types_defined_by(tcx.local_parent(item));
329
329
}
330
330
}
331
331
tcx.arena.alloc_from_iter(collector.opaques)
0 commit comments