@@ -801,8 +801,8 @@ fn should_encode_mir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> (bool, bool) {
801801 DefKind :: AnonConst | DefKind :: AssocConst | DefKind :: Static | DefKind :: Const => {
802802 ( true , false )
803803 }
804- // Closures and functions
805- DefKind :: Closure | DefKind :: AssocFn | DefKind :: Fn => {
804+ // Full-fledged functions
805+ DefKind :: AssocFn | DefKind :: Fn => {
806806 let generics = tcx. generics_of ( def_id) ;
807807 let needs_inline = ( generics. requires_monomorphization ( tcx)
808808 || tcx. codegen_fn_attrs ( def_id) . requests_inline ( ) )
@@ -812,6 +812,15 @@ fn should_encode_mir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> (bool, bool) {
812812 let always_encode_mir = tcx. sess . opts . debugging_opts . always_encode_mir ;
813813 ( is_const_fn, needs_inline || always_encode_mir)
814814 }
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+ }
815824 // Generators require optimized MIR to compute layout.
816825 DefKind :: Generator => ( false , true ) ,
817826 // The others don't have MIR.
@@ -1206,18 +1215,18 @@ impl EncodeContext<'a, 'tcx> {
12061215 }
12071216 if encode_const {
12081217 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+ }
12091223 }
12101224 record ! ( self . tables. promoted_mir[ def_id. to_def_id( ) ] <- self . tcx. promoted_mir( def_id) ) ;
12111225
12121226 let unused = self . tcx . unused_generic_params ( def_id) ;
12131227 if !unused. is_empty ( ) {
12141228 record ! ( self . tables. unused_generic_params[ def_id. to_def_id( ) ] <- unused) ;
12151229 }
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- }
12211230 }
12221231 }
12231232
0 commit comments