@@ -7,7 +7,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
7
7
use rustc_data_structures:: stable_hasher:: StableHasher ;
8
8
use rustc_data_structures:: sync:: { join, Lrc } ;
9
9
use rustc_hir as hir;
10
- use rustc_hir:: def:: { CtorKind , DefKind } ;
10
+ use rustc_hir:: def:: { CtorOf , DefKind } ;
11
11
use rustc_hir:: def_id:: { CrateNum , DefId , DefIndex , LocalDefId , CRATE_DEF_INDEX , LOCAL_CRATE } ;
12
12
use rustc_hir:: definitions:: DefPathData ;
13
13
use rustc_hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
@@ -725,6 +725,14 @@ impl EncodeContext<'a, 'tcx> {
725
725
let hir = tcx. hir ( ) ;
726
726
for local_id in hir. iter_local_def_id ( ) {
727
727
let def_id = local_id. to_def_id ( ) ;
728
+ let def_kind = tcx. opt_def_kind ( local_id) ;
729
+ let def_kind = if let Some ( def_kind) = def_kind { def_kind } else { continue } ;
730
+ record ! ( self . tables. def_kind[ def_id] <- match def_kind {
731
+ // Replace Ctor by the enclosing object to avoid leaking details in children crates.
732
+ DefKind :: Ctor ( CtorOf :: Struct , _) => DefKind :: Struct ,
733
+ DefKind :: Ctor ( CtorOf :: Variant , _) => DefKind :: Variant ,
734
+ def_kind => def_kind,
735
+ } ) ;
728
736
record ! ( self . tables. span[ def_id] <- tcx. def_span( def_id) ) ;
729
737
}
730
738
}
@@ -752,7 +760,6 @@ impl EncodeContext<'a, 'tcx> {
752
760
is_non_exhaustive : variant. is_field_list_non_exhaustive ( ) ,
753
761
} ;
754
762
755
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Variant ) ;
756
763
record ! ( self . tables. kind[ def_id] <- EntryKind :: Variant ( self . lazy( data) ) ) ;
757
764
record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
758
765
record ! ( self . tables. attributes[ def_id] <- & self . tcx. get_attrs( def_id) [ ..] ) ;
@@ -792,7 +799,6 @@ impl EncodeContext<'a, 'tcx> {
792
799
is_non_exhaustive : variant. is_field_list_non_exhaustive ( ) ,
793
800
} ;
794
801
795
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Variant ) ;
796
802
record ! ( self . tables. kind[ def_id] <- EntryKind :: Variant ( self . lazy( data) ) ) ;
797
803
record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
798
804
self . encode_stability ( def_id) ;
@@ -844,7 +850,6 @@ impl EncodeContext<'a, 'tcx> {
844
850
expansion : tcx. hir ( ) . definitions ( ) . expansion_that_defined ( local_def_id) ,
845
851
} ;
846
852
847
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Mod ) ;
848
853
record ! ( self . tables. kind[ def_id] <- EntryKind :: Mod ( self . lazy( data) ) ) ;
849
854
record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
850
855
record ! ( self . tables. attributes[ def_id] <- attrs) ;
@@ -875,7 +880,6 @@ impl EncodeContext<'a, 'tcx> {
875
880
let variant_id = tcx. hir ( ) . local_def_id_to_hir_id ( variant. def_id . expect_local ( ) ) ;
876
881
let variant_data = tcx. hir ( ) . expect_variant_data ( variant_id) ;
877
882
878
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Field ) ;
879
883
record ! ( self . tables. kind[ def_id] <- EntryKind :: Field ) ;
880
884
record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
881
885
record ! ( self . tables. attributes[ def_id] <- variant_data. fields( ) [ field_index] . attrs) ;
@@ -901,7 +905,6 @@ impl EncodeContext<'a, 'tcx> {
901
905
is_non_exhaustive : variant. is_field_list_non_exhaustive ( ) ,
902
906
} ;
903
907
904
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Struct ) ;
905
908
record ! ( self . tables. kind[ def_id] <- EntryKind :: Struct ( self . lazy( data) , adt_def. repr) ) ;
906
909
record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
907
910
record ! ( self . tables. expn_that_defined[ def_id] <- self . tcx. expansion_that_defined( def_id) ) ;
@@ -976,7 +979,6 @@ impl EncodeContext<'a, 'tcx> {
976
979
) ;
977
980
let rendered_const = self . lazy ( RenderedConst ( rendered) ) ;
978
981
979
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: AssocConst ) ;
980
982
record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocConst (
981
983
container,
982
984
Default :: default ( ) ,
@@ -997,7 +999,6 @@ impl EncodeContext<'a, 'tcx> {
997
999
} else {
998
1000
bug ! ( )
999
1001
} ;
1000
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: AssocFn ) ;
1001
1002
record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocFn ( self . lazy( AssocFnData {
1002
1003
fn_data,
1003
1004
container,
@@ -1006,7 +1007,6 @@ impl EncodeContext<'a, 'tcx> {
1006
1007
}
1007
1008
ty:: AssocKind :: Type => {
1008
1009
self . encode_explicit_item_bounds ( def_id) ;
1009
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: AssocTy ) ;
1010
1010
record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocType ( container) ) ;
1011
1011
}
1012
1012
}
@@ -1084,7 +1084,6 @@ impl EncodeContext<'a, 'tcx> {
1084
1084
if let hir:: ImplItemKind :: Const ( _, body_id) = ast_item. kind {
1085
1085
let qualifs = self . tcx . at ( ast_item. span ) . mir_const_qualif ( def_id) ;
1086
1086
1087
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: AssocConst ) ;
1088
1087
record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocConst (
1089
1088
container,
1090
1089
qualifs,
@@ -1104,15 +1103,13 @@ impl EncodeContext<'a, 'tcx> {
1104
1103
} else {
1105
1104
bug ! ( )
1106
1105
} ;
1107
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: AssocFn ) ;
1108
1106
record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocFn ( self . lazy( AssocFnData {
1109
1107
fn_data,
1110
1108
container,
1111
1109
has_self: impl_item. fn_has_self_parameter,
1112
1110
} ) ) ) ;
1113
1111
}
1114
1112
ty:: AssocKind :: Type => {
1115
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: AssocTy ) ;
1116
1113
record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocType ( container) ) ;
1117
1114
}
1118
1115
}
@@ -1251,19 +1248,12 @@ impl EncodeContext<'a, 'tcx> {
1251
1248
1252
1249
self . encode_ident_span ( def_id, item. ident ) ;
1253
1250
1254
- let ( def_kind, entry_kind) = match item. kind {
1255
- hir:: ItemKind :: Static ( _, hir:: Mutability :: Mut , _) => {
1256
- ( DefKind :: Static , EntryKind :: MutStatic )
1257
- }
1258
- hir:: ItemKind :: Static ( _, hir:: Mutability :: Not , _) => {
1259
- ( DefKind :: Static , EntryKind :: ImmStatic )
1260
- }
1251
+ let entry_kind = match item. kind {
1252
+ hir:: ItemKind :: Static ( _, hir:: Mutability :: Mut , _) => EntryKind :: MutStatic ,
1253
+ hir:: ItemKind :: Static ( _, hir:: Mutability :: Not , _) => EntryKind :: ImmStatic ,
1261
1254
hir:: ItemKind :: Const ( _, body_id) => {
1262
1255
let qualifs = self . tcx . at ( item. span ) . mir_const_qualif ( def_id) ;
1263
- (
1264
- DefKind :: Const ,
1265
- EntryKind :: Const ( qualifs, self . encode_rendered_const_for_body ( body_id) ) ,
1266
- )
1256
+ EntryKind :: Const ( qualifs, self . encode_rendered_const_for_body ( body_id) )
1267
1257
}
1268
1258
hir:: ItemKind :: Fn ( ref sig, .., body) => {
1269
1259
let data = FnData {
@@ -1272,21 +1262,19 @@ impl EncodeContext<'a, 'tcx> {
1272
1262
param_names : self . encode_fn_param_names_for_body ( body) ,
1273
1263
} ;
1274
1264
1275
- ( DefKind :: Fn , EntryKind :: Fn ( self . lazy ( data) ) )
1265
+ EntryKind :: Fn ( self . lazy ( data) )
1276
1266
}
1277
1267
hir:: ItemKind :: Mod ( ref m) => {
1278
1268
return self . encode_info_for_mod ( item. hir_id , m, & item. attrs ) ;
1279
1269
}
1280
- hir:: ItemKind :: ForeignMod { .. } => ( DefKind :: ForeignMod , EntryKind :: ForeignMod ) ,
1281
- hir:: ItemKind :: GlobalAsm ( ..) => ( DefKind :: GlobalAsm , EntryKind :: GlobalAsm ) ,
1282
- hir:: ItemKind :: TyAlias ( ..) => ( DefKind :: TyAlias , EntryKind :: Type ) ,
1270
+ hir:: ItemKind :: ForeignMod { .. } => EntryKind :: ForeignMod ,
1271
+ hir:: ItemKind :: GlobalAsm ( ..) => EntryKind :: GlobalAsm ,
1272
+ hir:: ItemKind :: TyAlias ( ..) => EntryKind :: Type ,
1283
1273
hir:: ItemKind :: OpaqueTy ( ..) => {
1284
1274
self . encode_explicit_item_bounds ( def_id) ;
1285
- ( DefKind :: OpaqueTy , EntryKind :: OpaqueTy )
1286
- }
1287
- hir:: ItemKind :: Enum ( ..) => {
1288
- ( DefKind :: Enum , EntryKind :: Enum ( self . tcx . adt_def ( def_id) . repr ) )
1275
+ EntryKind :: OpaqueTy
1289
1276
}
1277
+ hir:: ItemKind :: Enum ( ..) => EntryKind :: Enum ( self . tcx . adt_def ( def_id) . repr ) ,
1290
1278
hir:: ItemKind :: Struct ( ref struct_def, _) => {
1291
1279
let adt_def = self . tcx . adt_def ( def_id) ;
1292
1280
let variant = adt_def. non_enum_variant ( ) ;
@@ -1298,31 +1286,29 @@ impl EncodeContext<'a, 'tcx> {
1298
1286
. ctor_hir_id ( )
1299
1287
. map ( |ctor_hir_id| self . tcx . hir ( ) . local_def_id ( ctor_hir_id) . local_def_index ) ;
1300
1288
1301
- let ek = EntryKind :: Struct (
1289
+ EntryKind :: Struct (
1302
1290
self . lazy ( VariantData {
1303
1291
ctor_kind : variant. ctor_kind ,
1304
1292
discr : variant. discr ,
1305
1293
ctor,
1306
1294
is_non_exhaustive : variant. is_field_list_non_exhaustive ( ) ,
1307
1295
} ) ,
1308
1296
adt_def. repr ,
1309
- ) ;
1310
- ( DefKind :: Struct , ek)
1297
+ )
1311
1298
}
1312
1299
hir:: ItemKind :: Union ( ..) => {
1313
1300
let adt_def = self . tcx . adt_def ( def_id) ;
1314
1301
let variant = adt_def. non_enum_variant ( ) ;
1315
1302
1316
- let ek = EntryKind :: Union (
1303
+ EntryKind :: Union (
1317
1304
self . lazy ( VariantData {
1318
1305
ctor_kind : variant. ctor_kind ,
1319
1306
discr : variant. discr ,
1320
1307
ctor : None ,
1321
1308
is_non_exhaustive : variant. is_field_list_non_exhaustive ( ) ,
1322
1309
} ) ,
1323
1310
adt_def. repr ,
1324
- ) ;
1325
- ( DefKind :: Union , ek)
1311
+ )
1326
1312
}
1327
1313
hir:: ItemKind :: Impl ( hir:: Impl { defaultness, .. } ) => {
1328
1314
let trait_ref = self . tcx . impl_trait_ref ( def_id) ;
@@ -1352,7 +1338,7 @@ impl EncodeContext<'a, 'tcx> {
1352
1338
let data =
1353
1339
ImplData { polarity, defaultness, parent_impl : parent, coerce_unsized_info } ;
1354
1340
1355
- ( DefKind :: Impl , EntryKind :: Impl ( self . lazy ( data) ) )
1341
+ EntryKind :: Impl ( self . lazy ( data) )
1356
1342
}
1357
1343
hir:: ItemKind :: Trait ( ..) => {
1358
1344
let trait_def = self . tcx . trait_def ( def_id) ;
@@ -1364,14 +1350,13 @@ impl EncodeContext<'a, 'tcx> {
1364
1350
specialization_kind : trait_def. specialization_kind ,
1365
1351
} ;
1366
1352
1367
- ( DefKind :: Trait , EntryKind :: Trait ( self . lazy ( data) ) )
1353
+ EntryKind :: Trait ( self . lazy ( data) )
1368
1354
}
1369
- hir:: ItemKind :: TraitAlias ( ..) => ( DefKind :: TraitAlias , EntryKind :: TraitAlias ) ,
1355
+ hir:: ItemKind :: TraitAlias ( ..) => EntryKind :: TraitAlias ,
1370
1356
hir:: ItemKind :: ExternCrate ( _) | hir:: ItemKind :: Use ( ..) => {
1371
1357
bug ! ( "cannot encode info for item {:?}" , item)
1372
1358
}
1373
1359
} ;
1374
- record ! ( self . tables. def_kind[ def_id] <- def_kind) ;
1375
1360
record ! ( self . tables. kind[ def_id] <- entry_kind) ;
1376
1361
record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
1377
1362
record ! ( self . tables. attributes[ def_id] <- item. attrs) ;
@@ -1491,7 +1476,6 @@ impl EncodeContext<'a, 'tcx> {
1491
1476
/// Serialize the text of exported macros
1492
1477
fn encode_info_for_macro_def ( & mut self , macro_def : & hir:: MacroDef < ' _ > ) {
1493
1478
let def_id = self . tcx . hir ( ) . local_def_id ( macro_def. hir_id ) . to_def_id ( ) ;
1494
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Macro ( MacroKind :: Bang ) ) ;
1495
1479
record ! ( self . tables. kind[ def_id] <- EntryKind :: MacroDef ( self . lazy( macro_def. ast. clone( ) ) ) ) ;
1496
1480
record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
1497
1481
record ! ( self . tables. attributes[ def_id] <- macro_def. attrs) ;
@@ -1500,14 +1484,7 @@ impl EncodeContext<'a, 'tcx> {
1500
1484
self . encode_deprecation ( def_id) ;
1501
1485
}
1502
1486
1503
- fn encode_info_for_generic_param (
1504
- & mut self ,
1505
- def_id : DefId ,
1506
- def_kind : DefKind ,
1507
- kind : EntryKind ,
1508
- encode_type : bool ,
1509
- ) {
1510
- record ! ( self . tables. def_kind[ def_id] <- def_kind) ;
1487
+ fn encode_info_for_generic_param ( & mut self , def_id : DefId , kind : EntryKind , encode_type : bool ) {
1511
1488
record ! ( self . tables. kind[ def_id] <- kind) ;
1512
1489
if encode_type {
1513
1490
self . encode_item_type ( def_id) ;
@@ -1525,12 +1502,10 @@ impl EncodeContext<'a, 'tcx> {
1525
1502
match ty. kind ( ) {
1526
1503
ty:: Generator ( ..) => {
1527
1504
let data = self . tcx . generator_kind ( def_id) . unwrap ( ) ;
1528
- record ! ( self . tables. def_kind[ def_id. to_def_id( ) ] <- DefKind :: Generator ) ;
1529
1505
record ! ( self . tables. kind[ def_id. to_def_id( ) ] <- EntryKind :: Generator ( data) ) ;
1530
1506
}
1531
1507
1532
1508
ty:: Closure ( ..) => {
1533
- record ! ( self . tables. def_kind[ def_id. to_def_id( ) ] <- DefKind :: Closure ) ;
1534
1509
record ! ( self . tables. kind[ def_id. to_def_id( ) ] <- EntryKind :: Closure ) ;
1535
1510
}
1536
1511
@@ -1559,7 +1534,6 @@ impl EncodeContext<'a, 'tcx> {
1559
1534
let const_data = self . encode_rendered_const_for_body ( body_id) ;
1560
1535
let qualifs = self . tcx . mir_const_qualif ( def_id) ;
1561
1536
1562
- record ! ( self . tables. def_kind[ def_id. to_def_id( ) ] <- DefKind :: AnonConst ) ;
1563
1537
record ! ( self . tables. kind[ def_id. to_def_id( ) ] <- EntryKind :: AnonConst ( qualifs, const_data) ) ;
1564
1538
self . encode_item_type ( def_id. to_def_id ( ) ) ;
1565
1539
self . encode_generics ( def_id. to_def_id ( ) ) ;
@@ -1822,19 +1796,15 @@ impl EncodeContext<'a, 'tcx> {
1822
1796
} ,
1823
1797
param_names : self . encode_fn_param_names ( names) ,
1824
1798
} ;
1825
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Fn ) ;
1826
1799
record ! ( self . tables. kind[ def_id] <- EntryKind :: ForeignFn ( self . lazy( data) ) ) ;
1827
1800
}
1828
1801
hir:: ForeignItemKind :: Static ( _, hir:: Mutability :: Mut ) => {
1829
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Static ) ;
1830
1802
record ! ( self . tables. kind[ def_id] <- EntryKind :: ForeignMutStatic ) ;
1831
1803
}
1832
1804
hir:: ForeignItemKind :: Static ( _, hir:: Mutability :: Not ) => {
1833
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Static ) ;
1834
1805
record ! ( self . tables. kind[ def_id] <- EntryKind :: ForeignImmStatic ) ;
1835
1806
}
1836
1807
hir:: ForeignItemKind :: Type => {
1837
- record ! ( self . tables. def_kind[ def_id] <- DefKind :: ForeignTy ) ;
1838
1808
record ! ( self . tables. kind[ def_id] <- EntryKind :: ForeignType ) ;
1839
1809
}
1840
1810
}
@@ -1912,7 +1882,6 @@ impl EncodeContext<'a, 'tcx> {
1912
1882
GenericParamKind :: Type { ref default, .. } => {
1913
1883
self . encode_info_for_generic_param (
1914
1884
def_id. to_def_id ( ) ,
1915
- DefKind :: TyParam ,
1916
1885
EntryKind :: TypeParam ,
1917
1886
default. is_some ( ) ,
1918
1887
) ;
@@ -1923,7 +1892,6 @@ impl EncodeContext<'a, 'tcx> {
1923
1892
GenericParamKind :: Const { .. } => {
1924
1893
self . encode_info_for_generic_param (
1925
1894
def_id. to_def_id ( ) ,
1926
- DefKind :: ConstParam ,
1927
1895
EntryKind :: ConstParam ,
1928
1896
true ,
1929
1897
) ;
0 commit comments