@@ -801,8 +801,8 @@ fn should_encode_mir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> (bool, bool) {
801
801
DefKind :: AnonConst | DefKind :: AssocConst | DefKind :: Static | DefKind :: Const => {
802
802
( true , false )
803
803
}
804
- // Closures and functions
805
- DefKind :: Closure | DefKind :: AssocFn | DefKind :: Fn => {
804
+ // Full-fledged functions
805
+ DefKind :: AssocFn | DefKind :: Fn => {
806
806
let generics = tcx. generics_of ( def_id) ;
807
807
let needs_inline = ( generics. requires_monomorphization ( tcx)
808
808
|| tcx. codegen_fn_attrs ( def_id) . requests_inline ( ) )
@@ -812,6 +812,15 @@ fn should_encode_mir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> (bool, bool) {
812
812
let always_encode_mir = tcx. sess . opts . debugging_opts . always_encode_mir ;
813
813
( is_const_fn, needs_inline || always_encode_mir)
814
814
}
815
+ // Closures can't be const fn.
816
+ DefKind :: Closure => {
817
+ let generics = tcx. generics_of ( def_id) ;
818
+ let needs_inline = ( generics. requires_monomorphization ( tcx)
819
+ || tcx. codegen_fn_attrs ( def_id) . requests_inline ( ) )
820
+ && tcx. sess . opts . output_types . should_codegen ( ) ;
821
+ let always_encode_mir = tcx. sess . opts . debugging_opts . always_encode_mir ;
822
+ ( false , needs_inline || always_encode_mir)
823
+ }
815
824
// Generators require optimized MIR to compute layout.
816
825
DefKind :: Generator => ( false , true ) ,
817
826
// The others don't have MIR.
@@ -1206,18 +1215,18 @@ impl EncodeContext<'a, 'tcx> {
1206
1215
}
1207
1216
if encode_const {
1208
1217
record ! ( self . tables. mir_for_ctfe[ def_id. to_def_id( ) ] <- self . tcx. mir_for_ctfe( def_id) ) ;
1218
+
1219
+ let abstract_const = self . tcx . mir_abstract_const ( def_id) ;
1220
+ if let Ok ( Some ( abstract_const) ) = abstract_const {
1221
+ record ! ( self . tables. mir_abstract_consts[ def_id. to_def_id( ) ] <- abstract_const) ;
1222
+ }
1209
1223
}
1210
1224
record ! ( self . tables. promoted_mir[ def_id. to_def_id( ) ] <- self . tcx. promoted_mir( def_id) ) ;
1211
1225
1212
1226
let unused = self . tcx . unused_generic_params ( def_id) ;
1213
1227
if !unused. is_empty ( ) {
1214
1228
record ! ( self . tables. unused_generic_params[ def_id. to_def_id( ) ] <- unused) ;
1215
1229
}
1216
-
1217
- let abstract_const = self . tcx . mir_abstract_const ( def_id) ;
1218
- if let Ok ( Some ( abstract_const) ) = abstract_const {
1219
- record ! ( self . tables. mir_abstract_consts[ def_id. to_def_id( ) ] <- abstract_const) ;
1220
- }
1221
1230
}
1222
1231
}
1223
1232
0 commit comments