@@ -57,11 +57,11 @@ fn should_explore(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
57
57
| DefKind :: InlineConst
58
58
| DefKind :: ExternCrate
59
59
| DefKind :: Use
60
+ | DefKind :: Ctor ( ..)
60
61
| DefKind :: ForeignMod => true ,
61
62
62
63
DefKind :: TyParam
63
64
| DefKind :: ConstParam
64
- | DefKind :: Ctor ( ..)
65
65
| DefKind :: Field
66
66
| DefKind :: LifetimeParam
67
67
| DefKind :: Closure
@@ -103,8 +103,6 @@ struct MarkSymbolVisitor<'tcx> {
103
103
repr_has_repr_simd : bool ,
104
104
in_pat : bool ,
105
105
ignore_variant_stack : Vec < DefId > ,
106
- // maps from tuple struct constructors to tuple struct items
107
- struct_constructors : LocalDefIdMap < LocalDefId > ,
108
106
// maps from ADTs to ignored derived traits (e.g. Debug and Clone)
109
107
// and the span of their respective impl (i.e., part of the derive
110
108
// macro)
@@ -123,7 +121,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
123
121
124
122
fn check_def_id ( & mut self , def_id : DefId ) {
125
123
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) {
127
125
self . worklist . push ( ( def_id, ComesFromAllowExpect :: No ) ) ;
128
126
}
129
127
self . live_symbols . insert ( def_id) ;
@@ -348,17 +346,19 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
348
346
continue ;
349
347
}
350
348
351
- let ( id, comes_from_allow_expect) = work;
349
+ let ( mut id, comes_from_allow_expect) = work;
352
350
353
351
// Avoid accessing the HIR for the synthesized associated type generated for RPITITs.
354
352
if self . tcx . is_impl_trait_in_trait ( id. to_def_id ( ) ) {
355
353
self . live_symbols . insert ( id) ;
356
354
continue ;
357
355
}
358
356
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
+ }
362
362
363
363
// When using `#[allow]` or `#[expect]` of `dead_code`, we do a QOL improvement
364
364
// 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(
751
751
fn check_item < ' tcx > (
752
752
tcx : TyCtxt < ' tcx > ,
753
753
worklist : & mut Vec < ( LocalDefId , ComesFromAllowExpect ) > ,
754
- struct_constructors : & mut LocalDefIdMap < LocalDefId > ,
755
754
unsolved_items : & mut Vec < ( hir:: ItemId , LocalDefId ) > ,
756
755
id : hir:: ItemId ,
757
756
) {
@@ -769,12 +768,6 @@ fn check_item<'tcx>(
769
768
enum_def. variants . iter ( ) . map ( |variant| ( variant. def_id , comes_from_allow) ) ,
770
769
) ;
771
770
}
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
- }
778
771
}
779
772
}
780
773
DefKind :: Impl { of_trait } => {
@@ -802,14 +795,6 @@ fn check_item<'tcx>(
802
795
}
803
796
}
804
797
}
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
- }
813
798
DefKind :: GlobalAsm => {
814
799
// global_asm! is always live.
815
800
worklist. push ( ( id. owner_id . def_id , ComesFromAllowExpect :: No ) ) ;
@@ -859,15 +844,9 @@ fn check_foreign_item(
859
844
860
845
fn create_and_seed_worklist (
861
846
tcx : TyCtxt < ' _ > ,
862
- ) -> (
863
- Vec < ( LocalDefId , ComesFromAllowExpect ) > ,
864
- LocalDefIdMap < LocalDefId > ,
865
- Vec < ( hir:: ItemId , LocalDefId ) > ,
866
- ) {
847
+ ) -> ( Vec < ( LocalDefId , ComesFromAllowExpect ) > , Vec < ( hir:: ItemId , LocalDefId ) > ) {
867
848
let effective_visibilities = & tcx. effective_visibilities ( ( ) ) ;
868
- // see `MarkSymbolVisitor::struct_constructors`
869
849
let mut unsolved_impl_item = Vec :: new ( ) ;
870
- let mut struct_constructors = Default :: default ( ) ;
871
850
let mut worklist = effective_visibilities
872
851
. iter ( )
873
852
. filter_map ( |( & id, effective_vis) | {
@@ -885,7 +864,7 @@ fn create_and_seed_worklist(
885
864
886
865
let crate_items = tcx. hir_crate_items ( ( ) ) ;
887
866
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) ;
889
868
}
890
869
891
870
for id in crate_items. trait_items ( ) {
@@ -896,14 +875,14 @@ fn create_and_seed_worklist(
896
875
check_foreign_item ( tcx, & mut worklist, id) ;
897
876
}
898
877
899
- ( worklist, struct_constructors , unsolved_impl_item)
878
+ ( worklist, unsolved_impl_item)
900
879
}
901
880
902
881
fn live_symbols_and_ignored_derived_traits (
903
882
tcx : TyCtxt < ' _ > ,
904
883
( ) : ( ) ,
905
884
) -> ( 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) ;
907
886
let mut symbol_visitor = MarkSymbolVisitor {
908
887
worklist,
909
888
tcx,
@@ -913,7 +892,6 @@ fn live_symbols_and_ignored_derived_traits(
913
892
repr_has_repr_simd : false ,
914
893
in_pat : false ,
915
894
ignore_variant_stack : vec ! [ ] ,
916
- struct_constructors,
917
895
ignored_derived_traits : Default :: default ( ) ,
918
896
} ;
919
897
symbol_visitor. mark_live_symbols ( ) ;
0 commit comments