@@ -1094,43 +1094,6 @@ fn should_encode_const(def_kind: DefKind) -> bool {
1094
1094
}
1095
1095
}
1096
1096
1097
- fn should_encode_constness ( def_kind : DefKind ) -> bool {
1098
- match def_kind {
1099
- DefKind :: Struct
1100
- | DefKind :: Union
1101
- | DefKind :: Enum
1102
- | DefKind :: Trait
1103
- | DefKind :: AssocTy
1104
- | DefKind :: Fn
1105
- | DefKind :: Const
1106
- | DefKind :: Static ( ..)
1107
- | DefKind :: Ctor ( ..)
1108
- | DefKind :: AssocFn
1109
- | DefKind :: AssocConst
1110
- | DefKind :: AnonConst
1111
- | DefKind :: InlineConst
1112
- | DefKind :: OpaqueTy
1113
- | DefKind :: ImplTraitPlaceholder
1114
- | DefKind :: Impl
1115
- | DefKind :: Closure
1116
- | DefKind :: Generator
1117
- | DefKind :: TyAlias => true ,
1118
- DefKind :: Variant
1119
- | DefKind :: TraitAlias
1120
- | DefKind :: ForeignTy
1121
- | DefKind :: Field
1122
- | DefKind :: TyParam
1123
- | DefKind :: Mod
1124
- | DefKind :: ForeignMod
1125
- | DefKind :: ConstParam
1126
- | DefKind :: Macro ( ..)
1127
- | DefKind :: Use
1128
- | DefKind :: LifetimeParam
1129
- | DefKind :: GlobalAsm
1130
- | DefKind :: ExternCrate => false ,
1131
- }
1132
- }
1133
-
1134
1097
fn should_encode_trait_impl_trait_tys < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> bool {
1135
1098
if tcx. def_kind ( def_id) != DefKind :: AssocFn {
1136
1099
return false ;
@@ -1239,9 +1202,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1239
1202
{
1240
1203
record ! ( self . tables. trait_impl_trait_tys[ def_id] <- table) ;
1241
1204
}
1242
- if should_encode_constness ( def_kind) {
1243
- self . tables . constness . set ( def_id. index , tcx. constness ( def_id) ) ;
1244
- }
1245
1205
}
1246
1206
let inherent_impls = tcx. crate_inherent_impls ( ( ) ) ;
1247
1207
for ( def_id, implementations) in inherent_impls. inherent_impls . iter ( ) {
@@ -1269,6 +1229,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1269
1229
} ;
1270
1230
1271
1231
record ! ( self . tables. variant_data[ def_id] <- data) ;
1232
+ self . tables . constness . set ( def_id. index , hir:: Constness :: Const ) ;
1272
1233
record_array ! ( self . tables. children[ def_id] <- variant. fields. iter( ) . map( |f| {
1273
1234
assert!( f. did. is_local( ) ) ;
1274
1235
f. did. index
@@ -1296,6 +1257,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1296
1257
} ;
1297
1258
1298
1259
record ! ( self . tables. variant_data[ def_id] <- data) ;
1260
+ self . tables . constness . set ( def_id. index , hir:: Constness :: Const ) ;
1299
1261
if variant. ctor_kind == CtorKind :: Fn {
1300
1262
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1301
1263
}
@@ -1359,6 +1321,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1359
1321
1360
1322
record ! ( self . tables. repr_options[ def_id] <- adt_def. repr( ) ) ;
1361
1323
record ! ( self . tables. variant_data[ def_id] <- data) ;
1324
+ self . tables . constness . set ( def_id. index , hir:: Constness :: Const ) ;
1362
1325
if variant. ctor_kind == CtorKind :: Fn {
1363
1326
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1364
1327
}
@@ -1394,6 +1357,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1394
1357
}
1395
1358
} ;
1396
1359
self . tables . asyncness . set ( def_id. index , m_sig. header . asyncness ) ;
1360
+ self . tables . constness . set ( def_id. index , hir:: Constness :: NotConst ) ;
1397
1361
}
1398
1362
ty:: AssocKind :: Type => {
1399
1363
self . encode_explicit_item_bounds ( def_id) ;
@@ -1418,6 +1382,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1418
1382
let hir:: ImplItemKind :: Fn ( ref sig, body) = ast_item. kind else { bug ! ( ) } ;
1419
1383
self . tables . asyncness . set ( def_id. index , sig. header . asyncness ) ;
1420
1384
record_array ! ( self . tables. fn_arg_names[ def_id] <- self . tcx. hir( ) . body_param_names( body) ) ;
1385
+ // Can be inside `impl const Trait`, so using sig.header.constness is not reliable
1386
+ let constness = if self . tcx . is_const_fn_raw ( def_id) {
1387
+ hir:: Constness :: Const
1388
+ } else {
1389
+ hir:: Constness :: NotConst
1390
+ } ;
1391
+ self . tables . constness . set ( def_id. index , constness) ;
1421
1392
}
1422
1393
ty:: AssocKind :: Const | ty:: AssocKind :: Type => { }
1423
1394
}
@@ -1555,6 +1526,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1555
1526
hir:: ItemKind :: Fn ( ref sig, .., body) => {
1556
1527
self . tables . asyncness . set ( def_id. index , sig. header . asyncness ) ;
1557
1528
record_array ! ( self . tables. fn_arg_names[ def_id] <- self . tcx. hir( ) . body_param_names( body) ) ;
1529
+ self . tables . constness . set ( def_id. index , sig. header . constness ) ;
1558
1530
}
1559
1531
hir:: ItemKind :: Macro ( ref macro_def, _) => {
1560
1532
if macro_def. macro_rules {
@@ -1575,6 +1547,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1575
1547
hir:: ItemKind :: Struct ( ref struct_def, _) => {
1576
1548
let adt_def = self . tcx . adt_def ( def_id) ;
1577
1549
record ! ( self . tables. repr_options[ def_id] <- adt_def. repr( ) ) ;
1550
+ self . tables . constness . set ( def_id. index , hir:: Constness :: Const ) ;
1578
1551
1579
1552
// Encode def_ids for each field and method
1580
1553
// for methods, write all the stuff get_trait_method
@@ -1603,8 +1576,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1603
1576
is_non_exhaustive: variant. is_field_list_non_exhaustive( ) ,
1604
1577
} ) ;
1605
1578
}
1606
- hir:: ItemKind :: Impl ( hir:: Impl { defaultness, .. } ) => {
1579
+ hir:: ItemKind :: Impl ( hir:: Impl { defaultness, constness , .. } ) => {
1607
1580
self . tables . impl_defaultness . set ( def_id. index , * defaultness) ;
1581
+ self . tables . constness . set ( def_id. index , * constness) ;
1608
1582
1609
1583
let trait_ref = self . tcx . impl_trait_ref ( def_id) ;
1610
1584
if let Some ( trait_ref) = trait_ref {
0 commit comments