@@ -875,7 +875,7 @@ fn should_encode_span(def_kind: DefKind) -> bool {
875
875
}
876
876
}
877
877
878
- fn should_encode_attrs ( def_kind : DefKind ) -> bool {
878
+ fn should_encode_attrs ( def_kind : DefKind , is_coroutine : bool ) -> bool {
879
879
match def_kind {
880
880
DefKind :: Mod
881
881
| DefKind :: Struct
@@ -899,7 +899,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
899
899
// closures from upstream crates, too. This is used by
900
900
// https://github.com/model-checking/kani and is not a performance
901
901
// or maintenance issue for us.
902
- DefKind :: Closure => true ,
902
+ DefKind :: Closure => !is_coroutine ,
903
903
DefKind :: TyParam
904
904
| DefKind :: ConstParam
905
905
| DefKind :: Ctor ( ..)
@@ -1058,7 +1058,7 @@ fn should_encode_mir(
1058
1058
| DefKind :: Static ( ..)
1059
1059
| DefKind :: Const => ( true , false ) ,
1060
1060
// 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 ) ,
1062
1062
// Full-fledged functions + closures
1063
1063
DefKind :: AssocFn | DefKind :: Fn | DefKind :: Closure => {
1064
1064
let generics = tcx. generics_of ( def_id) ;
@@ -1241,11 +1241,11 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
1241
1241
}
1242
1242
}
1243
1243
1244
- fn should_encode_constness ( def_kind : DefKind ) -> bool {
1244
+ fn should_encode_constness ( def_kind : DefKind , is_coroutine : bool ) -> bool {
1245
1245
match def_kind {
1246
+ DefKind :: Closure => !is_coroutine,
1246
1247
DefKind :: Fn
1247
1248
| DefKind :: AssocFn
1248
- | DefKind :: Closure
1249
1249
| DefKind :: Impl { of_trait : true }
1250
1250
| DefKind :: Variant
1251
1251
| DefKind :: Ctor ( ..) => true ,
@@ -1358,12 +1358,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1358
1358
for local_id in tcx. iter_local_def_id ( ) {
1359
1359
let def_id = local_id. to_def_id ( ) ;
1360
1360
let def_kind = tcx. def_kind ( local_id) ;
1361
+ let is_coroutine = def_kind == DefKind :: Closure && tcx. is_coroutine ( local_id) ;
1361
1362
self . tables . def_kind . set_some ( def_id. index , def_kind) ;
1362
1363
if should_encode_span ( def_kind) {
1363
1364
let def_span = tcx. def_span ( local_id) ;
1364
1365
record ! ( self . tables. def_span[ def_id] <- def_span) ;
1365
1366
}
1366
- if should_encode_attrs ( def_kind) {
1367
+ if should_encode_attrs ( def_kind, is_coroutine ) {
1367
1368
self . encode_attrs ( local_id) ;
1368
1369
}
1369
1370
if should_encode_expn_that_defined ( def_kind) {
@@ -1418,7 +1419,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1418
1419
if should_encode_type ( tcx, local_id, def_kind) && !anon_const_without_hir {
1419
1420
record ! ( self . tables. type_of[ def_id] <- self . tcx. type_of( def_id) ) ;
1420
1421
}
1421
- if should_encode_constness ( def_kind) {
1422
+ if should_encode_constness ( def_kind, is_coroutine ) {
1422
1423
self . tables . constness . set_some ( def_id. index , self . tcx . constness ( def_id) ) ;
1423
1424
}
1424
1425
if let DefKind :: Fn | DefKind :: AssocFn = def_kind {
@@ -1639,7 +1640,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1639
1640
record ! ( self . tables. closure_saved_names_of_captured_variables[ def_id. to_def_id( ) ]
1640
1641
<- tcx. closure_saved_names_of_captured_variables( def_id) ) ;
1641
1642
1642
- if self . tcx . is_coroutine ( def_id. to_def_id ( ) )
1643
+ if self . tcx . is_coroutine ( def_id)
1643
1644
&& let Some ( witnesses) = tcx. mir_coroutine_witnesses ( def_id)
1644
1645
{
1645
1646
record ! ( self . tables. mir_coroutine_witnesses[ def_id. to_def_id( ) ] <- witnesses) ;
@@ -1666,7 +1667,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1666
1667
}
1667
1668
record ! ( self . tables. promoted_mir[ def_id. to_def_id( ) ] <- tcx. promoted_mir( def_id) ) ;
1668
1669
1669
- if self . tcx . is_coroutine ( def_id. to_def_id ( ) )
1670
+ if self . tcx . is_coroutine ( def_id)
1670
1671
&& let Some ( witnesses) = tcx. mir_coroutine_witnesses ( def_id)
1671
1672
{
1672
1673
record ! ( self . tables. mir_coroutine_witnesses[ def_id. to_def_id( ) ] <- witnesses) ;
0 commit comments