@@ -7,7 +7,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
77use rustc_data_structures:: stable_hasher:: StableHasher ;
88use rustc_data_structures:: sync:: { join, Lrc } ;
99use rustc_hir as hir;
10- use rustc_hir:: def:: { CtorKind , DefKind } ;
10+ use rustc_hir:: def:: { CtorOf , DefKind } ;
1111use rustc_hir:: def_id:: { CrateNum , DefId , DefIndex , LocalDefId , CRATE_DEF_INDEX , LOCAL_CRATE } ;
1212use rustc_hir:: definitions:: DefPathData ;
1313use rustc_hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
@@ -725,6 +725,14 @@ impl EncodeContext<'a, 'tcx> {
725725 let hir = tcx. hir ( ) ;
726726 for local_id in hir. iter_local_def_id ( ) {
727727 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+ } ) ;
728736 record ! ( self . tables. span[ def_id] <- tcx. def_span( def_id) ) ;
729737 }
730738 }
@@ -752,7 +760,6 @@ impl EncodeContext<'a, 'tcx> {
752760 is_non_exhaustive : variant. is_field_list_non_exhaustive ( ) ,
753761 } ;
754762
755- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Variant ) ;
756763 record ! ( self . tables. kind[ def_id] <- EntryKind :: Variant ( self . lazy( data) ) ) ;
757764 record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
758765 record ! ( self . tables. attributes[ def_id] <- & self . tcx. get_attrs( def_id) [ ..] ) ;
@@ -792,7 +799,6 @@ impl EncodeContext<'a, 'tcx> {
792799 is_non_exhaustive : variant. is_field_list_non_exhaustive ( ) ,
793800 } ;
794801
795- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Variant ) ;
796802 record ! ( self . tables. kind[ def_id] <- EntryKind :: Variant ( self . lazy( data) ) ) ;
797803 record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
798804 self . encode_stability ( def_id) ;
@@ -844,7 +850,6 @@ impl EncodeContext<'a, 'tcx> {
844850 expansion : tcx. hir ( ) . definitions ( ) . expansion_that_defined ( local_def_id) ,
845851 } ;
846852
847- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Mod ) ;
848853 record ! ( self . tables. kind[ def_id] <- EntryKind :: Mod ( self . lazy( data) ) ) ;
849854 record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
850855 record ! ( self . tables. attributes[ def_id] <- attrs) ;
@@ -875,7 +880,6 @@ impl EncodeContext<'a, 'tcx> {
875880 let variant_id = tcx. hir ( ) . local_def_id_to_hir_id ( variant. def_id . expect_local ( ) ) ;
876881 let variant_data = tcx. hir ( ) . expect_variant_data ( variant_id) ;
877882
878- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Field ) ;
879883 record ! ( self . tables. kind[ def_id] <- EntryKind :: Field ) ;
880884 record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
881885 record ! ( self . tables. attributes[ def_id] <- variant_data. fields( ) [ field_index] . attrs) ;
@@ -901,7 +905,6 @@ impl EncodeContext<'a, 'tcx> {
901905 is_non_exhaustive : variant. is_field_list_non_exhaustive ( ) ,
902906 } ;
903907
904- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Struct ) ;
905908 record ! ( self . tables. kind[ def_id] <- EntryKind :: Struct ( self . lazy( data) , adt_def. repr) ) ;
906909 record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
907910 record ! ( self . tables. expn_that_defined[ def_id] <- self . tcx. expansion_that_defined( def_id) ) ;
@@ -976,7 +979,6 @@ impl EncodeContext<'a, 'tcx> {
976979 ) ;
977980 let rendered_const = self . lazy ( RenderedConst ( rendered) ) ;
978981
979- record ! ( self . tables. def_kind[ def_id] <- DefKind :: AssocConst ) ;
980982 record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocConst (
981983 container,
982984 Default :: default ( ) ,
@@ -997,7 +999,6 @@ impl EncodeContext<'a, 'tcx> {
997999 } else {
9981000 bug ! ( )
9991001 } ;
1000- record ! ( self . tables. def_kind[ def_id] <- DefKind :: AssocFn ) ;
10011002 record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocFn ( self . lazy( AssocFnData {
10021003 fn_data,
10031004 container,
@@ -1006,7 +1007,6 @@ impl EncodeContext<'a, 'tcx> {
10061007 }
10071008 ty:: AssocKind :: Type => {
10081009 self . encode_explicit_item_bounds ( def_id) ;
1009- record ! ( self . tables. def_kind[ def_id] <- DefKind :: AssocTy ) ;
10101010 record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocType ( container) ) ;
10111011 }
10121012 }
@@ -1084,7 +1084,6 @@ impl EncodeContext<'a, 'tcx> {
10841084 if let hir:: ImplItemKind :: Const ( _, body_id) = ast_item. kind {
10851085 let qualifs = self . tcx . at ( ast_item. span ) . mir_const_qualif ( def_id) ;
10861086
1087- record ! ( self . tables. def_kind[ def_id] <- DefKind :: AssocConst ) ;
10881087 record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocConst (
10891088 container,
10901089 qualifs,
@@ -1104,15 +1103,13 @@ impl EncodeContext<'a, 'tcx> {
11041103 } else {
11051104 bug ! ( )
11061105 } ;
1107- record ! ( self . tables. def_kind[ def_id] <- DefKind :: AssocFn ) ;
11081106 record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocFn ( self . lazy( AssocFnData {
11091107 fn_data,
11101108 container,
11111109 has_self: impl_item. fn_has_self_parameter,
11121110 } ) ) ) ;
11131111 }
11141112 ty:: AssocKind :: Type => {
1115- record ! ( self . tables. def_kind[ def_id] <- DefKind :: AssocTy ) ;
11161113 record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocType ( container) ) ;
11171114 }
11181115 }
@@ -1251,19 +1248,12 @@ impl EncodeContext<'a, 'tcx> {
12511248
12521249 self . encode_ident_span ( def_id, item. ident ) ;
12531250
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 ,
12611254 hir:: ItemKind :: Const ( _, body_id) => {
12621255 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) )
12671257 }
12681258 hir:: ItemKind :: Fn ( ref sig, .., body) => {
12691259 let data = FnData {
@@ -1272,21 +1262,19 @@ impl EncodeContext<'a, 'tcx> {
12721262 param_names : self . encode_fn_param_names_for_body ( body) ,
12731263 } ;
12741264
1275- ( DefKind :: Fn , EntryKind :: Fn ( self . lazy ( data) ) )
1265+ EntryKind :: Fn ( self . lazy ( data) )
12761266 }
12771267 hir:: ItemKind :: Mod ( ref m) => {
12781268 return self . encode_info_for_mod ( item. hir_id , m, & item. attrs ) ;
12791269 }
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 ,
12831273 hir:: ItemKind :: OpaqueTy ( ..) => {
12841274 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
12891276 }
1277+ hir:: ItemKind :: Enum ( ..) => EntryKind :: Enum ( self . tcx . adt_def ( def_id) . repr ) ,
12901278 hir:: ItemKind :: Struct ( ref struct_def, _) => {
12911279 let adt_def = self . tcx . adt_def ( def_id) ;
12921280 let variant = adt_def. non_enum_variant ( ) ;
@@ -1298,31 +1286,29 @@ impl EncodeContext<'a, 'tcx> {
12981286 . ctor_hir_id ( )
12991287 . map ( |ctor_hir_id| self . tcx . hir ( ) . local_def_id ( ctor_hir_id) . local_def_index ) ;
13001288
1301- let ek = EntryKind :: Struct (
1289+ EntryKind :: Struct (
13021290 self . lazy ( VariantData {
13031291 ctor_kind : variant. ctor_kind ,
13041292 discr : variant. discr ,
13051293 ctor,
13061294 is_non_exhaustive : variant. is_field_list_non_exhaustive ( ) ,
13071295 } ) ,
13081296 adt_def. repr ,
1309- ) ;
1310- ( DefKind :: Struct , ek)
1297+ )
13111298 }
13121299 hir:: ItemKind :: Union ( ..) => {
13131300 let adt_def = self . tcx . adt_def ( def_id) ;
13141301 let variant = adt_def. non_enum_variant ( ) ;
13151302
1316- let ek = EntryKind :: Union (
1303+ EntryKind :: Union (
13171304 self . lazy ( VariantData {
13181305 ctor_kind : variant. ctor_kind ,
13191306 discr : variant. discr ,
13201307 ctor : None ,
13211308 is_non_exhaustive : variant. is_field_list_non_exhaustive ( ) ,
13221309 } ) ,
13231310 adt_def. repr ,
1324- ) ;
1325- ( DefKind :: Union , ek)
1311+ )
13261312 }
13271313 hir:: ItemKind :: Impl ( hir:: Impl { defaultness, .. } ) => {
13281314 let trait_ref = self . tcx . impl_trait_ref ( def_id) ;
@@ -1352,7 +1338,7 @@ impl EncodeContext<'a, 'tcx> {
13521338 let data =
13531339 ImplData { polarity, defaultness, parent_impl : parent, coerce_unsized_info } ;
13541340
1355- ( DefKind :: Impl , EntryKind :: Impl ( self . lazy ( data) ) )
1341+ EntryKind :: Impl ( self . lazy ( data) )
13561342 }
13571343 hir:: ItemKind :: Trait ( ..) => {
13581344 let trait_def = self . tcx . trait_def ( def_id) ;
@@ -1364,14 +1350,13 @@ impl EncodeContext<'a, 'tcx> {
13641350 specialization_kind : trait_def. specialization_kind ,
13651351 } ;
13661352
1367- ( DefKind :: Trait , EntryKind :: Trait ( self . lazy ( data) ) )
1353+ EntryKind :: Trait ( self . lazy ( data) )
13681354 }
1369- hir:: ItemKind :: TraitAlias ( ..) => ( DefKind :: TraitAlias , EntryKind :: TraitAlias ) ,
1355+ hir:: ItemKind :: TraitAlias ( ..) => EntryKind :: TraitAlias ,
13701356 hir:: ItemKind :: ExternCrate ( _) | hir:: ItemKind :: Use ( ..) => {
13711357 bug ! ( "cannot encode info for item {:?}" , item)
13721358 }
13731359 } ;
1374- record ! ( self . tables. def_kind[ def_id] <- def_kind) ;
13751360 record ! ( self . tables. kind[ def_id] <- entry_kind) ;
13761361 record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
13771362 record ! ( self . tables. attributes[ def_id] <- item. attrs) ;
@@ -1491,7 +1476,6 @@ impl EncodeContext<'a, 'tcx> {
14911476 /// Serialize the text of exported macros
14921477 fn encode_info_for_macro_def ( & mut self , macro_def : & hir:: MacroDef < ' _ > ) {
14931478 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 ) ) ;
14951479 record ! ( self . tables. kind[ def_id] <- EntryKind :: MacroDef ( self . lazy( macro_def. ast. clone( ) ) ) ) ;
14961480 record ! ( self . tables. visibility[ def_id] <- self . tcx. visibility( def_id) ) ;
14971481 record ! ( self . tables. attributes[ def_id] <- macro_def. attrs) ;
@@ -1500,14 +1484,7 @@ impl EncodeContext<'a, 'tcx> {
15001484 self . encode_deprecation ( def_id) ;
15011485 }
15021486
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 ) {
15111488 record ! ( self . tables. kind[ def_id] <- kind) ;
15121489 if encode_type {
15131490 self . encode_item_type ( def_id) ;
@@ -1525,12 +1502,10 @@ impl EncodeContext<'a, 'tcx> {
15251502 match ty. kind ( ) {
15261503 ty:: Generator ( ..) => {
15271504 let data = self . tcx . generator_kind ( def_id) . unwrap ( ) ;
1528- record ! ( self . tables. def_kind[ def_id. to_def_id( ) ] <- DefKind :: Generator ) ;
15291505 record ! ( self . tables. kind[ def_id. to_def_id( ) ] <- EntryKind :: Generator ( data) ) ;
15301506 }
15311507
15321508 ty:: Closure ( ..) => {
1533- record ! ( self . tables. def_kind[ def_id. to_def_id( ) ] <- DefKind :: Closure ) ;
15341509 record ! ( self . tables. kind[ def_id. to_def_id( ) ] <- EntryKind :: Closure ) ;
15351510 }
15361511
@@ -1559,7 +1534,6 @@ impl EncodeContext<'a, 'tcx> {
15591534 let const_data = self . encode_rendered_const_for_body ( body_id) ;
15601535 let qualifs = self . tcx . mir_const_qualif ( def_id) ;
15611536
1562- record ! ( self . tables. def_kind[ def_id. to_def_id( ) ] <- DefKind :: AnonConst ) ;
15631537 record ! ( self . tables. kind[ def_id. to_def_id( ) ] <- EntryKind :: AnonConst ( qualifs, const_data) ) ;
15641538 self . encode_item_type ( def_id. to_def_id ( ) ) ;
15651539 self . encode_generics ( def_id. to_def_id ( ) ) ;
@@ -1822,19 +1796,15 @@ impl EncodeContext<'a, 'tcx> {
18221796 } ,
18231797 param_names : self . encode_fn_param_names ( names) ,
18241798 } ;
1825- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Fn ) ;
18261799 record ! ( self . tables. kind[ def_id] <- EntryKind :: ForeignFn ( self . lazy( data) ) ) ;
18271800 }
18281801 hir:: ForeignItemKind :: Static ( _, hir:: Mutability :: Mut ) => {
1829- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Static ) ;
18301802 record ! ( self . tables. kind[ def_id] <- EntryKind :: ForeignMutStatic ) ;
18311803 }
18321804 hir:: ForeignItemKind :: Static ( _, hir:: Mutability :: Not ) => {
1833- record ! ( self . tables. def_kind[ def_id] <- DefKind :: Static ) ;
18341805 record ! ( self . tables. kind[ def_id] <- EntryKind :: ForeignImmStatic ) ;
18351806 }
18361807 hir:: ForeignItemKind :: Type => {
1837- record ! ( self . tables. def_kind[ def_id] <- DefKind :: ForeignTy ) ;
18381808 record ! ( self . tables. kind[ def_id] <- EntryKind :: ForeignType ) ;
18391809 }
18401810 }
@@ -1912,7 +1882,6 @@ impl EncodeContext<'a, 'tcx> {
19121882 GenericParamKind :: Type { ref default, .. } => {
19131883 self . encode_info_for_generic_param (
19141884 def_id. to_def_id ( ) ,
1915- DefKind :: TyParam ,
19161885 EntryKind :: TypeParam ,
19171886 default. is_some ( ) ,
19181887 ) ;
@@ -1923,7 +1892,6 @@ impl EncodeContext<'a, 'tcx> {
19231892 GenericParamKind :: Const { .. } => {
19241893 self . encode_info_for_generic_param (
19251894 def_id. to_def_id ( ) ,
1926- DefKind :: ConstParam ,
19271895 EntryKind :: ConstParam ,
19281896 true ,
19291897 ) ;
0 commit comments