@@ -21,9 +21,8 @@ use rustc_const_eval::util;
21
21
use rustc_data_structures:: fx:: FxIndexSet ;
22
22
use rustc_data_structures:: steal:: Steal ;
23
23
use rustc_hir as hir;
24
- use rustc_hir:: def:: DefKind ;
24
+ use rustc_hir:: def:: { CtorKind , DefKind } ;
25
25
use rustc_hir:: def_id:: LocalDefId ;
26
- use rustc_hir:: intravisit:: { self , Visitor } ;
27
26
use rustc_index:: IndexVec ;
28
27
use rustc_middle:: mir:: {
29
28
AnalysisPhase , Body , CallSource , ClearCrossCrate , ConstOperand , ConstQualifs , LocalDecl ,
@@ -224,20 +223,27 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
224
223
// All body-owners have MIR associated with them.
225
224
let mut set: FxIndexSet < _ > = tcx. hir ( ) . body_owners ( ) . collect ( ) ;
226
225
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)
231
+ {
232
+ set. insert ( tcx. coroutine_by_move_body_def_id ( body_owner) . expect_local ( ) ) ;
233
+ }
231
234
}
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
+ }
236
244
}
237
- intravisit:: walk_struct_def ( self , v)
238
245
}
239
246
}
240
- tcx. hir ( ) . visit_all_item_likes_in_crate ( & mut GatherCtors { set : & mut set } ) ;
241
247
242
248
set
243
249
}
0 commit comments