@@ -45,15 +45,15 @@ fn should_explore(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
45
45
)
46
46
}
47
47
48
- /// Returns the local def id and def kind of the adt,
49
- /// if the given ty refers to one local adt definition.
50
- fn local_adt_def_of_ty < ' tcx > ( ty : & hir:: Ty < ' tcx > ) -> Option < ( LocalDefId , DefKind ) > {
48
+ /// Returns the local def id of the ADT if the given ty refers to a local one.
49
+ fn local_adt_def_of_ty < ' tcx > ( ty : & hir:: Ty < ' tcx > ) -> Option < LocalDefId > {
51
50
match ty. kind {
52
51
TyKind :: Path ( QPath :: Resolved ( _, path) ) => {
53
52
if let Res :: Def ( def_kind, def_id) = path. res
54
53
&& let Some ( local_def_id) = def_id. as_local ( )
54
+ && matches ! ( def_kind, DefKind :: Struct | DefKind :: Enum | DefKind :: Union )
55
55
{
56
- Some ( ( local_def_id, def_kind ) )
56
+ Some ( local_def_id)
57
57
} else {
58
58
None
59
59
}
@@ -485,7 +485,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
485
485
}
486
486
}
487
487
488
- /// Returns whether `local_def_id` is live or not.
488
+ /// Returns whether `local_def_id` is potentially alive or not.
489
489
/// `local_def_id` points to an impl or an impl item,
490
490
/// both impl and impl item that may be passed to this function are of a trait,
491
491
/// and added into the unsolved_items during `create_and_seed_worklist`
@@ -518,8 +518,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
518
518
519
519
// FIXME: legacy logic to check whether the function may construct `Self`,
520
520
// this can be removed after supporting marking ADTs appearing in patterns
521
- // as live, then we can check private impls of.
522
- // public traits directly
521
+ // as live, then we can check private impls of public traits directly
523
522
if let Some ( fn_sig) =
524
523
self . tcx . hir_fn_sig_by_hir_id ( self . tcx . local_def_id_to_hir_id ( local_def_id) )
525
524
&& matches ! ( fn_sig. decl. implicit_self, hir:: ImplicitSelfKind :: None )
@@ -529,10 +528,9 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
529
528
}
530
529
}
531
530
532
- // The impl/ impl item is used if the trait/ trait item is used and the ty is used.
533
- if let Some ( ( local_def_id, def_kind ) ) =
531
+ // The impl or impl item is used if the corresponding trait or trait item is used and the ty is used.
532
+ if let Some ( local_def_id) =
534
533
local_adt_def_of_ty ( self . tcx . hir_item ( impl_id) . expect_impl ( ) . self_ty )
535
- && matches ! ( def_kind, DefKind :: Struct | DefKind :: Enum | DefKind :: Union )
536
534
&& !self . live_symbols . contains ( & local_def_id)
537
535
{
538
536
return false ;
@@ -761,7 +759,6 @@ fn check_item<'tcx>(
761
759
unsolved_items. push ( ( id, id. owner_id . def_id ) ) ;
762
760
}
763
761
764
- // We access the Map here to get HirId from LocalDefId
765
762
for def_id in tcx. associated_item_def_ids ( id. owner_id ) {
766
763
let local_def_id = def_id. expect_local ( ) ;
767
764
@@ -774,11 +771,11 @@ fn check_item<'tcx>(
774
771
if !matches ! ( tcx. def_kind( local_def_id) , DefKind :: AssocFn ) {
775
772
worklist. push ( ( local_def_id, ComesFromAllowExpect :: No ) ) ;
776
773
} else {
777
- // We only care about assoc items of trait ,
778
- // because they cannot be visited directly
779
- // so we mark them based on the trait/trait item
780
- // and self ty are checked first and both live,
781
- // but inherent assoc items can be visited and marked directly.
774
+ // We only care about associated items of traits ,
775
+ // because they cannot be visited directly,
776
+ // so we later mark them as live if their corresponding traits
777
+ // or trait items and self types are both live,
778
+ // but inherent associated items can be visited and marked directly.
782
779
unsolved_items. push ( ( id, local_def_id) ) ;
783
780
}
784
781
}
0 commit comments