Skip to content

Commit 5fe639c

Browse files
Record synthetic MIR bodies in mir_keys
1 parent f69f4af commit 5fe639c

File tree

1 file changed

+18
-12
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+18
-12
lines changed

compiler/rustc_mir_transform/src/lib.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ use rustc_const_eval::util;
2121
use rustc_data_structures::fx::FxIndexSet;
2222
use rustc_data_structures::steal::Steal;
2323
use rustc_hir as hir;
24-
use rustc_hir::def::DefKind;
24+
use rustc_hir::def::{CtorKind, DefKind};
2525
use rustc_hir::def_id::LocalDefId;
26-
use rustc_hir::intravisit::{self, Visitor};
2726
use rustc_index::IndexVec;
2827
use rustc_middle::mir::{
2928
AnalysisPhase, Body, CallSource, ClearCrossCrate, ConstOperand, ConstQualifs, LocalDecl,
@@ -224,20 +223,27 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
224223
// All body-owners have MIR associated with them.
225224
let mut set: FxIndexSet<_> = tcx.hir().body_owners().collect();
226225

227-
// Additionally, tuple struct/variant constructors have MIR, but
228-
// they don't have a BodyId, so we need to build them separately.
229-
struct GatherCtors<'a> {
230-
set: &'a mut FxIndexSet<LocalDefId>,
226+
// Coroutine-closures (e.g. async closures) have an additional by-move MIR
227+
// body that isn't in the HIR.
228+
for body_owner in tcx.hir().body_owners() {
229+
if let DefKind::Closure = tcx.def_kind(body_owner)
230+
&& tcx.needs_coroutine_by_move_body_def_id(body_owner.to_def_id())
231+
{
232+
set.insert(tcx.coroutine_by_move_body_def_id(body_owner).expect_local());
233+
}
231234
}
232-
impl<'tcx> Visitor<'tcx> for GatherCtors<'_> {
233-
fn visit_variant_data(&mut self, v: &'tcx hir::VariantData<'tcx>) {
234-
if let hir::VariantData::Tuple(_, _, def_id) = *v {
235-
self.set.insert(def_id);
235+
236+
// tuple struct/variant constructors have MIR, but they don't have a BodyId,
237+
// so we need to build them separately.
238+
for item in tcx.hir_crate_items(()).free_items() {
239+
if let DefKind::Struct | DefKind::Enum = tcx.def_kind(item.owner_id) {
240+
for variant in tcx.adt_def(item.owner_id).variants() {
241+
if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
242+
set.insert(ctor_def_id.expect_local());
243+
}
236244
}
237-
intravisit::walk_struct_def(self, v)
238245
}
239246
}
240-
tcx.hir().visit_all_item_likes_in_crate(&mut GatherCtors { set: &mut set });
241247

242248
set
243249
}

0 commit comments

Comments
 (0)