Skip to content

Commit 1cf061b

Browse files
committed
Apply suggestions, squash before merging
1 parent faab5c6 commit 1cf061b

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

compiler/rustc_passes/src/dead.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ fn should_explore(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
4545
)
4646
}
4747

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> {
5150
match ty.kind {
5251
TyKind::Path(QPath::Resolved(_, path)) => {
5352
if let Res::Def(def_kind, def_id) = path.res
5453
&& let Some(local_def_id) = def_id.as_local()
54+
&& matches!(def_kind, DefKind::Struct | DefKind::Enum | DefKind::Union)
5555
{
56-
Some((local_def_id, def_kind))
56+
Some(local_def_id)
5757
} else {
5858
None
5959
}
@@ -485,7 +485,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
485485
}
486486
}
487487

488-
/// Returns whether `local_def_id` is live or not.
488+
/// Returns whether `local_def_id` is potentially alive or not.
489489
/// `local_def_id` points to an impl or an impl item,
490490
/// both impl and impl item that may be passed to this function are of a trait,
491491
/// and added into the unsolved_items during `create_and_seed_worklist`
@@ -518,8 +518,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
518518

519519
// FIXME: legacy logic to check whether the function may construct `Self`,
520520
// 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
523522
if let Some(fn_sig) =
524523
self.tcx.hir_fn_sig_by_hir_id(self.tcx.local_def_id_to_hir_id(local_def_id))
525524
&& matches!(fn_sig.decl.implicit_self, hir::ImplicitSelfKind::None)
@@ -529,10 +528,9 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
529528
}
530529
}
531530

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) =
534533
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)
536534
&& !self.live_symbols.contains(&local_def_id)
537535
{
538536
return false;
@@ -761,7 +759,6 @@ fn check_item<'tcx>(
761759
unsolved_items.push((id, id.owner_id.def_id));
762760
}
763761

764-
// We access the Map here to get HirId from LocalDefId
765762
for def_id in tcx.associated_item_def_ids(id.owner_id) {
766763
let local_def_id = def_id.expect_local();
767764

@@ -774,11 +771,11 @@ fn check_item<'tcx>(
774771
if !matches!(tcx.def_kind(local_def_id), DefKind::AssocFn) {
775772
worklist.push((local_def_id, ComesFromAllowExpect::No));
776773
} 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.
782779
unsolved_items.push((id, local_def_id));
783780
}
784781
}

0 commit comments

Comments
 (0)