|
4 | 4 | //! type trees, recording each relevant type along with its `TyKind` and |
5 | 5 | //! `LayoutShape`. These collected types are later transformed into |
6 | 6 | //! [`TypeMetadata`](super::schema::TypeMetadata) entries in the final output. |
7 | | -//! Note that some special kinds (closures, function definitions/pointers, and |
8 | | -//! coroutine witnesses) are traversed only to gather the types they reference |
9 | | -//! and are not themselves stored as entries in the type map. |
| 7 | +//! Note that some special kinds (function definitions/pointers and coroutine |
| 8 | +//! witnesses) are traversed only to gather the types they reference and are |
| 9 | +//! not themselves stored as entries in the type map. |
10 | 10 |
|
11 | 11 | extern crate rustc_middle; |
12 | 12 | extern crate rustc_smir; |
@@ -63,7 +63,13 @@ impl Visitor for TyCollector<'_> { |
63 | 63 | self.resolved.insert(*ty); |
64 | 64 | let instance = |
65 | 65 | Instance::resolve_closure(def, args, stable_mir::ty::ClosureKind::Fn).unwrap(); |
66 | | - self.visit_instance(instance) |
| 66 | + let control = self.visit_instance(instance); |
| 67 | + // Mirror other branches: record closure Ty only when traversal succeeds. |
| 68 | + if matches!(control, ControlFlow::Continue(_)) { |
| 69 | + let maybe_layout_shape = ty.layout().ok().map(|layout| layout.shape()); |
| 70 | + self.types.insert(*ty, (ty.kind(), maybe_layout_shape)); |
| 71 | + } |
| 72 | + control |
67 | 73 | } |
68 | 74 | // Break on CoroutineWitnesses, because they aren't expected when getting the layout |
69 | 75 | TyKind::RigidTy(RigidTy::CoroutineWitness(..)) => { |
|
0 commit comments