@@ -57,11 +57,11 @@ fn should_explore(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
5757 | DefKind :: InlineConst
5858 | DefKind :: ExternCrate
5959 | DefKind :: Use
60+ | DefKind :: Ctor ( ..)
6061 | DefKind :: ForeignMod => true ,
6162
6263 DefKind :: TyParam
6364 | DefKind :: ConstParam
64- | DefKind :: Ctor ( ..)
6565 | DefKind :: Field
6666 | DefKind :: LifetimeParam
6767 | DefKind :: Closure
@@ -103,8 +103,6 @@ struct MarkSymbolVisitor<'tcx> {
103103 repr_has_repr_simd : bool ,
104104 in_pat : bool ,
105105 ignore_variant_stack : Vec < DefId > ,
106- // maps from tuple struct constructors to tuple struct items
107- struct_constructors : LocalDefIdMap < LocalDefId > ,
108106 // maps from ADTs to ignored derived traits (e.g. Debug and Clone)
109107 // and the span of their respective impl (i.e., part of the derive
110108 // macro)
@@ -123,7 +121,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
123121
124122 fn check_def_id ( & mut self , def_id : DefId ) {
125123 if let Some ( def_id) = def_id. as_local ( ) {
126- if should_explore ( self . tcx , def_id) || self . struct_constructors . contains_key ( & def_id ) {
124+ if should_explore ( self . tcx , def_id) {
127125 self . worklist . push ( ( def_id, ComesFromAllowExpect :: No ) ) ;
128126 }
129127 self . live_symbols . insert ( def_id) ;
@@ -348,17 +346,19 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
348346 continue ;
349347 }
350348
351- let ( id, comes_from_allow_expect) = work;
349+ let ( mut id, comes_from_allow_expect) = work;
352350
353351 // Avoid accessing the HIR for the synthesized associated type generated for RPITITs.
354352 if self . tcx . is_impl_trait_in_trait ( id. to_def_id ( ) ) {
355353 self . live_symbols . insert ( id) ;
356354 continue ;
357355 }
358356
359- // in the case of tuple struct constructors we want to check the item, not the generated
360- // tuple struct constructor function
361- let id = self . struct_constructors . get ( & id) . copied ( ) . unwrap_or ( id) ;
357+ // in the case of tuple struct constructors we want to check the item,
358+ // not the generated tuple struct constructor function
359+ if let DefKind :: Ctor ( ..) = self . tcx . def_kind ( id) {
360+ id = self . tcx . local_parent ( id) ;
361+ }
362362
363363 // When using `#[allow]` or `#[expect]` of `dead_code`, we do a QOL improvement
364364 // by declaring fn calls, statics, ... within said items as live, as well as
@@ -751,7 +751,6 @@ fn has_allow_dead_code_or_lang_attr(
751751fn check_item < ' tcx > (
752752 tcx : TyCtxt < ' tcx > ,
753753 worklist : & mut Vec < ( LocalDefId , ComesFromAllowExpect ) > ,
754- struct_constructors : & mut LocalDefIdMap < LocalDefId > ,
755754 unsolved_items : & mut Vec < ( hir:: ItemId , LocalDefId ) > ,
756755 id : hir:: ItemId ,
757756) {
@@ -769,12 +768,6 @@ fn check_item<'tcx>(
769768 enum_def. variants . iter ( ) . map ( |variant| ( variant. def_id , comes_from_allow) ) ,
770769 ) ;
771770 }
772-
773- for variant in enum_def. variants {
774- if let Some ( ctor_def_id) = variant. data . ctor_def_id ( ) {
775- struct_constructors. insert ( ctor_def_id, variant. def_id ) ;
776- }
777- }
778771 }
779772 }
780773 DefKind :: Impl { of_trait } => {
@@ -802,14 +795,6 @@ fn check_item<'tcx>(
802795 }
803796 }
804797 }
805- DefKind :: Struct => {
806- let item = tcx. hir_item ( id) ;
807- if let hir:: ItemKind :: Struct ( _, _, ref variant_data) = item. kind
808- && let Some ( ctor_def_id) = variant_data. ctor_def_id ( )
809- {
810- struct_constructors. insert ( ctor_def_id, item. owner_id . def_id ) ;
811- }
812- }
813798 DefKind :: GlobalAsm => {
814799 // global_asm! is always live.
815800 worklist. push ( ( id. owner_id . def_id , ComesFromAllowExpect :: No ) ) ;
@@ -859,15 +844,9 @@ fn check_foreign_item(
859844
860845fn create_and_seed_worklist (
861846 tcx : TyCtxt < ' _ > ,
862- ) -> (
863- Vec < ( LocalDefId , ComesFromAllowExpect ) > ,
864- LocalDefIdMap < LocalDefId > ,
865- Vec < ( hir:: ItemId , LocalDefId ) > ,
866- ) {
847+ ) -> ( Vec < ( LocalDefId , ComesFromAllowExpect ) > , Vec < ( hir:: ItemId , LocalDefId ) > ) {
867848 let effective_visibilities = & tcx. effective_visibilities ( ( ) ) ;
868- // see `MarkSymbolVisitor::struct_constructors`
869849 let mut unsolved_impl_item = Vec :: new ( ) ;
870- let mut struct_constructors = Default :: default ( ) ;
871850 let mut worklist = effective_visibilities
872851 . iter ( )
873852 . filter_map ( |( & id, effective_vis) | {
@@ -885,7 +864,7 @@ fn create_and_seed_worklist(
885864
886865 let crate_items = tcx. hir_crate_items ( ( ) ) ;
887866 for id in crate_items. free_items ( ) {
888- check_item ( tcx, & mut worklist, & mut struct_constructors , & mut unsolved_impl_item, id) ;
867+ check_item ( tcx, & mut worklist, & mut unsolved_impl_item, id) ;
889868 }
890869
891870 for id in crate_items. trait_items ( ) {
@@ -896,14 +875,14 @@ fn create_and_seed_worklist(
896875 check_foreign_item ( tcx, & mut worklist, id) ;
897876 }
898877
899- ( worklist, struct_constructors , unsolved_impl_item)
878+ ( worklist, unsolved_impl_item)
900879}
901880
902881fn live_symbols_and_ignored_derived_traits (
903882 tcx : TyCtxt < ' _ > ,
904883 ( ) : ( ) ,
905884) -> ( LocalDefIdSet , LocalDefIdMap < FxIndexSet < DefId > > ) {
906- let ( worklist, struct_constructors , mut unsolved_items) = create_and_seed_worklist ( tcx) ;
885+ let ( worklist, mut unsolved_items) = create_and_seed_worklist ( tcx) ;
907886 let mut symbol_visitor = MarkSymbolVisitor {
908887 worklist,
909888 tcx,
@@ -913,7 +892,6 @@ fn live_symbols_and_ignored_derived_traits(
913892 repr_has_repr_simd : false ,
914893 in_pat : false ,
915894 ignore_variant_stack : vec ! [ ] ,
916- struct_constructors,
917895 ignored_derived_traits : Default :: default ( ) ,
918896 } ;
919897 symbol_visitor. mark_live_symbols ( ) ;
0 commit comments