@@ -875,7 +875,7 @@ fn should_encode_span(def_kind: DefKind) -> bool {
875875 }
876876}
877877
878- fn should_encode_attrs ( def_kind : DefKind ) -> bool {
878+ fn should_encode_attrs ( def_kind : DefKind , is_coroutine : bool ) -> bool {
879879 match def_kind {
880880 DefKind :: Mod
881881 | DefKind :: Struct
@@ -899,7 +899,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
899899 // closures from upstream crates, too. This is used by
900900 // https://github.com/model-checking/kani and is not a performance
901901 // or maintenance issue for us.
902- DefKind :: Closure => true ,
902+ DefKind :: Closure => !is_coroutine ,
903903 DefKind :: TyParam
904904 | DefKind :: ConstParam
905905 | DefKind :: Ctor ( ..)
@@ -1058,7 +1058,7 @@ fn should_encode_mir(
10581058 | DefKind :: Static ( ..)
10591059 | DefKind :: Const => ( true , false ) ,
10601060 // Coroutines require optimized MIR to compute layout.
1061- DefKind :: Closure if tcx. is_coroutine ( def_id. to_def_id ( ) ) => ( false , true ) ,
1061+ DefKind :: Closure if tcx. is_coroutine ( def_id) => ( false , true ) ,
10621062 // Full-fledged functions + closures
10631063 DefKind :: AssocFn | DefKind :: Fn | DefKind :: Closure => {
10641064 let generics = tcx. generics_of ( def_id) ;
@@ -1241,11 +1241,11 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
12411241 }
12421242}
12431243
1244- fn should_encode_constness ( def_kind : DefKind ) -> bool {
1244+ fn should_encode_constness ( def_kind : DefKind , is_coroutine : bool ) -> bool {
12451245 match def_kind {
1246+ DefKind :: Closure => !is_coroutine,
12461247 DefKind :: Fn
12471248 | DefKind :: AssocFn
1248- | DefKind :: Closure
12491249 | DefKind :: Impl { of_trait : true }
12501250 | DefKind :: Variant
12511251 | DefKind :: Ctor ( ..) => true ,
@@ -1358,12 +1358,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13581358 for local_id in tcx. iter_local_def_id ( ) {
13591359 let def_id = local_id. to_def_id ( ) ;
13601360 let def_kind = tcx. def_kind ( local_id) ;
1361+ let is_coroutine = def_kind == DefKind :: Closure && tcx. is_coroutine ( local_id) ;
13611362 self . tables . def_kind . set_some ( def_id. index , def_kind) ;
13621363 if should_encode_span ( def_kind) {
13631364 let def_span = tcx. def_span ( local_id) ;
13641365 record ! ( self . tables. def_span[ def_id] <- def_span) ;
13651366 }
1366- if should_encode_attrs ( def_kind) {
1367+ if should_encode_attrs ( def_kind, is_coroutine ) {
13671368 self . encode_attrs ( local_id) ;
13681369 }
13691370 if should_encode_expn_that_defined ( def_kind) {
@@ -1418,7 +1419,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14181419 if should_encode_type ( tcx, local_id, def_kind) && !anon_const_without_hir {
14191420 record ! ( self . tables. type_of[ def_id] <- self . tcx. type_of( def_id) ) ;
14201421 }
1421- if should_encode_constness ( def_kind) {
1422+ if should_encode_constness ( def_kind, is_coroutine ) {
14221423 self . tables . constness . set_some ( def_id. index , self . tcx . constness ( def_id) ) ;
14231424 }
14241425 if let DefKind :: Fn | DefKind :: AssocFn = def_kind {
@@ -1639,7 +1640,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16391640 record ! ( self . tables. closure_saved_names_of_captured_variables[ def_id. to_def_id( ) ]
16401641 <- tcx. closure_saved_names_of_captured_variables( def_id) ) ;
16411642
1642- if self . tcx . is_coroutine ( def_id. to_def_id ( ) )
1643+ if self . tcx . is_coroutine ( def_id)
16431644 && let Some ( witnesses) = tcx. mir_coroutine_witnesses ( def_id)
16441645 {
16451646 record ! ( self . tables. mir_coroutine_witnesses[ def_id. to_def_id( ) ] <- witnesses) ;
@@ -1666,7 +1667,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16661667 }
16671668 record ! ( self . tables. promoted_mir[ def_id. to_def_id( ) ] <- tcx. promoted_mir( def_id) ) ;
16681669
1669- if self . tcx . is_coroutine ( def_id. to_def_id ( ) )
1670+ if self . tcx . is_coroutine ( def_id)
16701671 && let Some ( witnesses) = tcx. mir_coroutine_witnesses ( def_id)
16711672 {
16721673 record ! ( self . tables. mir_coroutine_witnesses[ def_id. to_def_id( ) ] <- witnesses) ;
0 commit comments