@@ -861,7 +861,7 @@ fn should_encode_span(def_kind: DefKind) -> bool {
861861 }
862862}
863863
864- fn should_encode_attrs ( def_kind : DefKind ) -> bool {
864+ fn should_encode_attrs ( def_kind : DefKind , is_coroutine : bool ) -> bool {
865865 match def_kind {
866866 DefKind :: Mod
867867 | DefKind :: Struct
@@ -885,7 +885,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
885885 // closures from upstream crates, too. This is used by
886886 // https://github.com/model-checking/kani and is not a performance
887887 // or maintenance issue for us.
888- DefKind :: Closure => true ,
888+ DefKind :: Closure => !is_coroutine ,
889889 DefKind :: TyParam
890890 | DefKind :: ConstParam
891891 | DefKind :: Ctor ( ..)
@@ -1044,7 +1044,7 @@ fn should_encode_mir(
10441044 | DefKind :: Static ( ..)
10451045 | DefKind :: Const => ( true , false ) ,
10461046 // Coroutines require optimized MIR to compute layout.
1047- DefKind :: Closure if tcx. is_coroutine ( def_id. to_def_id ( ) ) => ( false , true ) ,
1047+ DefKind :: Closure if tcx. is_coroutine ( def_id) => ( false , true ) ,
10481048 // Full-fledged functions + closures
10491049 DefKind :: AssocFn | DefKind :: Fn | DefKind :: Closure => {
10501050 let generics = tcx. generics_of ( def_id) ;
@@ -1227,11 +1227,11 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
12271227 }
12281228}
12291229
1230- fn should_encode_constness ( def_kind : DefKind ) -> bool {
1230+ fn should_encode_constness ( def_kind : DefKind , is_coroutine : bool ) -> bool {
12311231 match def_kind {
1232+ DefKind :: Closure => !is_coroutine,
12321233 DefKind :: Fn
12331234 | DefKind :: AssocFn
1234- | DefKind :: Closure
12351235 | DefKind :: Impl { of_trait : true }
12361236 | DefKind :: Variant
12371237 | DefKind :: Ctor ( ..) => true ,
@@ -1344,12 +1344,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13441344 for local_id in tcx. iter_local_def_id ( ) {
13451345 let def_id = local_id. to_def_id ( ) ;
13461346 let def_kind = tcx. def_kind ( local_id) ;
1347+ let is_coroutine = def_kind == DefKind :: Closure && tcx. is_coroutine ( local_id) ;
13471348 self . tables . def_kind . set_some ( def_id. index , def_kind) ;
13481349 if should_encode_span ( def_kind) {
13491350 let def_span = tcx. def_span ( local_id) ;
13501351 record ! ( self . tables. def_span[ def_id] <- def_span) ;
13511352 }
1352- if should_encode_attrs ( def_kind) {
1353+ if should_encode_attrs ( def_kind, is_coroutine ) {
13531354 self . encode_attrs ( local_id) ;
13541355 }
13551356 if should_encode_expn_that_defined ( def_kind) {
@@ -1404,7 +1405,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14041405 if should_encode_type ( tcx, local_id, def_kind) && !anon_const_without_hir {
14051406 record ! ( self . tables. type_of[ def_id] <- self . tcx. type_of( def_id) ) ;
14061407 }
1407- if should_encode_constness ( def_kind) {
1408+ if should_encode_constness ( def_kind, is_coroutine ) {
14081409 self . tables . constness . set_some ( def_id. index , self . tcx . constness ( def_id) ) ;
14091410 }
14101411 if let DefKind :: Fn | DefKind :: AssocFn = def_kind {
@@ -1625,7 +1626,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16251626 record ! ( self . tables. closure_saved_names_of_captured_variables[ def_id. to_def_id( ) ]
16261627 <- tcx. closure_saved_names_of_captured_variables( def_id) ) ;
16271628
1628- if self . tcx . is_coroutine ( def_id. to_def_id ( ) )
1629+ if self . tcx . is_coroutine ( def_id)
16291630 && let Some ( witnesses) = tcx. mir_coroutine_witnesses ( def_id)
16301631 {
16311632 record ! ( self . tables. mir_coroutine_witnesses[ def_id. to_def_id( ) ] <- witnesses) ;
@@ -1652,7 +1653,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16521653 }
16531654 record ! ( self . tables. promoted_mir[ def_id. to_def_id( ) ] <- tcx. promoted_mir( def_id) ) ;
16541655
1655- if self . tcx . is_coroutine ( def_id. to_def_id ( ) )
1656+ if self . tcx . is_coroutine ( def_id)
16561657 && let Some ( witnesses) = tcx. mir_coroutine_witnesses ( def_id)
16571658 {
16581659 record ! ( self . tables. mir_coroutine_witnesses[ def_id. to_def_id( ) ] <- witnesses) ;
0 commit comments