@@ -861,7 +861,7 @@ fn should_encode_span(def_kind: DefKind) -> bool {
861
861
}
862
862
}
863
863
864
- fn should_encode_attrs ( def_kind : DefKind ) -> bool {
864
+ fn should_encode_attrs ( def_kind : DefKind , is_coroutine : bool ) -> bool {
865
865
match def_kind {
866
866
DefKind :: Mod
867
867
| DefKind :: Struct
@@ -885,7 +885,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
885
885
// closures from upstream crates, too. This is used by
886
886
// https://github.com/model-checking/kani and is not a performance
887
887
// or maintenance issue for us.
888
- DefKind :: Closure => true ,
888
+ DefKind :: Closure => !is_coroutine ,
889
889
DefKind :: TyParam
890
890
| DefKind :: ConstParam
891
891
| DefKind :: Ctor ( ..)
@@ -1044,7 +1044,7 @@ fn should_encode_mir(
1044
1044
| DefKind :: Static ( ..)
1045
1045
| DefKind :: Const => ( true , false ) ,
1046
1046
// 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 ) ,
1048
1048
// Full-fledged functions + closures
1049
1049
DefKind :: AssocFn | DefKind :: Fn | DefKind :: Closure => {
1050
1050
let generics = tcx. generics_of ( def_id) ;
@@ -1227,11 +1227,11 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
1227
1227
}
1228
1228
}
1229
1229
1230
- fn should_encode_constness ( def_kind : DefKind ) -> bool {
1230
+ fn should_encode_constness ( def_kind : DefKind , is_coroutine : bool ) -> bool {
1231
1231
match def_kind {
1232
+ DefKind :: Closure => !is_coroutine,
1232
1233
DefKind :: Fn
1233
1234
| DefKind :: AssocFn
1234
- | DefKind :: Closure
1235
1235
| DefKind :: Impl { of_trait : true }
1236
1236
| DefKind :: Variant
1237
1237
| DefKind :: Ctor ( ..) => true ,
@@ -1344,12 +1344,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1344
1344
for local_id in tcx. iter_local_def_id ( ) {
1345
1345
let def_id = local_id. to_def_id ( ) ;
1346
1346
let def_kind = tcx. def_kind ( local_id) ;
1347
+ let is_coroutine = def_kind == DefKind :: Closure && tcx. is_coroutine ( local_id) ;
1347
1348
self . tables . def_kind . set_some ( def_id. index , def_kind) ;
1348
1349
if should_encode_span ( def_kind) {
1349
1350
let def_span = tcx. def_span ( local_id) ;
1350
1351
record ! ( self . tables. def_span[ def_id] <- def_span) ;
1351
1352
}
1352
- if should_encode_attrs ( def_kind) {
1353
+ if should_encode_attrs ( def_kind, is_coroutine ) {
1353
1354
self . encode_attrs ( local_id) ;
1354
1355
}
1355
1356
if should_encode_expn_that_defined ( def_kind) {
@@ -1404,7 +1405,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1404
1405
if should_encode_type ( tcx, local_id, def_kind) && !anon_const_without_hir {
1405
1406
record ! ( self . tables. type_of[ def_id] <- self . tcx. type_of( def_id) ) ;
1406
1407
}
1407
- if should_encode_constness ( def_kind) {
1408
+ if should_encode_constness ( def_kind, is_coroutine ) {
1408
1409
self . tables . constness . set_some ( def_id. index , self . tcx . constness ( def_id) ) ;
1409
1410
}
1410
1411
if let DefKind :: Fn | DefKind :: AssocFn = def_kind {
@@ -1625,7 +1626,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1625
1626
record ! ( self . tables. closure_saved_names_of_captured_variables[ def_id. to_def_id( ) ]
1626
1627
<- tcx. closure_saved_names_of_captured_variables( def_id) ) ;
1627
1628
1628
- if self . tcx . is_coroutine ( def_id. to_def_id ( ) )
1629
+ if self . tcx . is_coroutine ( def_id)
1629
1630
&& let Some ( witnesses) = tcx. mir_coroutine_witnesses ( def_id)
1630
1631
{
1631
1632
record ! ( self . tables. mir_coroutine_witnesses[ def_id. to_def_id( ) ] <- witnesses) ;
@@ -1652,7 +1653,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1652
1653
}
1653
1654
record ! ( self . tables. promoted_mir[ def_id. to_def_id( ) ] <- tcx. promoted_mir( def_id) ) ;
1654
1655
1655
- if self . tcx . is_coroutine ( def_id. to_def_id ( ) )
1656
+ if self . tcx . is_coroutine ( def_id)
1656
1657
&& let Some ( witnesses) = tcx. mir_coroutine_witnesses ( def_id)
1657
1658
{
1658
1659
record ! ( self . tables. mir_coroutine_witnesses[ def_id. to_def_id( ) ] <- witnesses) ;
0 commit comments