@@ -1059,6 +1059,43 @@ fn should_encode_const(def_kind: DefKind) -> bool {
1059
1059
}
1060
1060
}
1061
1061
1062
+ fn should_encode_constness ( def_kind : DefKind ) -> bool {
1063
+ match def_kind {
1064
+ DefKind :: Struct
1065
+ | DefKind :: Union
1066
+ | DefKind :: Enum
1067
+ | DefKind :: Trait
1068
+ | DefKind :: AssocTy
1069
+ | DefKind :: Fn
1070
+ | DefKind :: Const
1071
+ | DefKind :: Static ( ..)
1072
+ | DefKind :: Ctor ( ..)
1073
+ | DefKind :: AssocFn
1074
+ | DefKind :: AssocConst
1075
+ | DefKind :: AnonConst
1076
+ | DefKind :: InlineConst
1077
+ | DefKind :: OpaqueTy
1078
+ | DefKind :: ImplTraitPlaceholder
1079
+ | DefKind :: Impl
1080
+ | DefKind :: Closure
1081
+ | DefKind :: Generator => true ,
1082
+ DefKind :: Variant
1083
+ | DefKind :: TyAlias
1084
+ | DefKind :: TraitAlias
1085
+ | DefKind :: ForeignTy
1086
+ | DefKind :: Field
1087
+ | DefKind :: TyParam
1088
+ | DefKind :: Mod
1089
+ | DefKind :: ForeignMod
1090
+ | DefKind :: ConstParam
1091
+ | DefKind :: Macro ( ..)
1092
+ | DefKind :: Use
1093
+ | DefKind :: LifetimeParam
1094
+ | DefKind :: GlobalAsm
1095
+ | DefKind :: ExternCrate => false ,
1096
+ }
1097
+ }
1098
+
1062
1099
fn should_encode_trait_impl_trait_tys < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> bool {
1063
1100
if tcx. def_kind ( def_id) != DefKind :: AssocFn {
1064
1101
return false ;
@@ -1165,6 +1202,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1165
1202
{
1166
1203
record ! ( self . tables. trait_impl_trait_tys[ def_id] <- table) ;
1167
1204
}
1205
+ if should_encode_constness ( def_kind) {
1206
+ self . tables . constness . set ( def_id. index , tcx. constness ( def_id) ) ;
1207
+ }
1168
1208
}
1169
1209
let inherent_impls = tcx. crate_inherent_impls ( ( ) ) ;
1170
1210
for ( def_id, implementations) in inherent_impls. inherent_impls . iter ( ) {
@@ -1192,7 +1232,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1192
1232
} ;
1193
1233
1194
1234
record ! ( self . tables. variant_data[ def_id] <- data) ;
1195
- self . tables . constness . set ( def_id. index , hir:: Constness :: Const ) ;
1196
1235
record_array ! ( self . tables. children[ def_id] <- variant. fields. iter( ) . map( |f| {
1197
1236
assert!( f. did. is_local( ) ) ;
1198
1237
f. did. index
@@ -1220,7 +1259,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1220
1259
} ;
1221
1260
1222
1261
record ! ( self . tables. variant_data[ def_id] <- data) ;
1223
- self . tables . constness . set ( def_id. index , hir:: Constness :: Const ) ;
1224
1262
if variant. ctor_kind == CtorKind :: Fn {
1225
1263
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1226
1264
}
@@ -1284,7 +1322,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1284
1322
1285
1323
record ! ( self . tables. repr_options[ def_id] <- adt_def. repr( ) ) ;
1286
1324
record ! ( self . tables. variant_data[ def_id] <- data) ;
1287
- self . tables . constness . set ( def_id. index , hir:: Constness :: Const ) ;
1288
1325
if variant. ctor_kind == CtorKind :: Fn {
1289
1326
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1290
1327
}
@@ -1320,7 +1357,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1320
1357
}
1321
1358
} ;
1322
1359
self . tables . asyncness . set ( def_id. index , m_sig. header . asyncness ) ;
1323
- self . tables . constness . set ( def_id. index , hir:: Constness :: NotConst ) ;
1324
1360
}
1325
1361
ty:: AssocKind :: Type => {
1326
1362
self . encode_explicit_item_bounds ( def_id) ;
@@ -1345,13 +1381,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1345
1381
let hir:: ImplItemKind :: Fn ( ref sig, body) = ast_item. kind else { bug ! ( ) } ;
1346
1382
self . tables . asyncness . set ( def_id. index , sig. header . asyncness ) ;
1347
1383
record_array ! ( self . tables. fn_arg_names[ def_id] <- self . tcx. hir( ) . body_param_names( body) ) ;
1348
- // Can be inside `impl const Trait`, so using sig.header.constness is not reliable
1349
- let constness = if self . tcx . is_const_fn_raw ( def_id) {
1350
- hir:: Constness :: Const
1351
- } else {
1352
- hir:: Constness :: NotConst
1353
- } ;
1354
- self . tables . constness . set ( def_id. index , constness) ;
1355
1384
}
1356
1385
ty:: AssocKind :: Const | ty:: AssocKind :: Type => { }
1357
1386
}
@@ -1474,7 +1503,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1474
1503
hir:: ItemKind :: Fn ( ref sig, .., body) => {
1475
1504
self . tables . asyncness . set ( def_id. index , sig. header . asyncness ) ;
1476
1505
record_array ! ( self . tables. fn_arg_names[ def_id] <- self . tcx. hir( ) . body_param_names( body) ) ;
1477
- self . tables . constness . set ( def_id. index , sig. header . constness ) ;
1478
1506
}
1479
1507
hir:: ItemKind :: Macro ( ref macro_def, _) => {
1480
1508
if macro_def. macro_rules {
@@ -1495,7 +1523,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1495
1523
hir:: ItemKind :: Struct ( ref struct_def, _) => {
1496
1524
let adt_def = self . tcx . adt_def ( def_id) ;
1497
1525
record ! ( self . tables. repr_options[ def_id] <- adt_def. repr( ) ) ;
1498
- self . tables . constness . set ( def_id. index , hir:: Constness :: Const ) ;
1499
1526
1500
1527
// Encode def_ids for each field and method
1501
1528
// for methods, write all the stuff get_trait_method
@@ -1524,9 +1551,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1524
1551
is_non_exhaustive: variant. is_field_list_non_exhaustive( ) ,
1525
1552
} ) ;
1526
1553
}
1527
- hir:: ItemKind :: Impl ( hir:: Impl { defaultness, constness , .. } ) => {
1554
+ hir:: ItemKind :: Impl ( hir:: Impl { defaultness, .. } ) => {
1528
1555
self . tables . impl_defaultness . set ( def_id. index , * defaultness) ;
1529
- self . tables . constness . set ( def_id. index , * constness) ;
1530
1556
1531
1557
let trait_ref = self . tcx . impl_trait_ref ( def_id) ;
1532
1558
if let Some ( trait_ref) = trait_ref {
0 commit comments