Skip to content

Commit

Permalink
Revert "Rollup merge of #127017 - mu001999-contrib:dead/enhance, r=pn…
Browse files Browse the repository at this point in the history
…kfelix"

This reverts commit a70dc29, reversing
changes made to ceae371.
  • Loading branch information
compiler-errors committed Jul 30, 2024
1 parent efdf219 commit 8a0cd61
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 87 deletions.
32 changes: 10 additions & 22 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,7 @@ impl Publicness {
}
}

fn adt_of<'tcx>(ty: &hir::Ty<'tcx>) -> Option<(LocalDefId, DefKind)> {
match ty.kind {
TyKind::Path(hir::QPath::Resolved(_, path)) => {
if let Res::Def(def_kind, def_id) = path.res
&& let Some(local_def_id) = def_id.as_local()
{
Some((local_def_id, def_kind))
} else {
None
}
}
TyKind::Slice(ty) | TyKind::Array(ty, _) => adt_of(ty),
TyKind::Ptr(ty) | TyKind::Ref(_, ty) => adt_of(ty.ty),
_ => None,
}
}

fn struct_all_fields_are_public(tcx: TyCtxt<'_>, id: LocalDefId) -> bool {
fn struct_all_fields_are_public(tcx: TyCtxt<'_>, id: DefId) -> bool {
// treat PhantomData and positional ZST as public,
// we don't want to lint types which only have them,
// cause it's a common way to use such types to check things like well-formedness
Expand All @@ -97,7 +80,10 @@ fn struct_all_fields_are_public(tcx: TyCtxt<'_>, id: LocalDefId) -> bool {
/// for enum and union, just check they are public,
/// and doesn't solve types like &T for now, just skip them
fn ty_ref_to_pub_struct(tcx: TyCtxt<'_>, ty: &hir::Ty<'_>) -> Publicness {
if let Some((def_id, def_kind)) = adt_of(ty) {
if let TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind
&& let Res::Def(def_kind, def_id) = path.res
&& def_id.is_local()
{
return match def_kind {
DefKind::Enum | DefKind::Union => {
let ty_is_public = tcx.visibility(def_id).is_public();
Expand Down Expand Up @@ -580,8 +566,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
}

fn impl_item_with_used_self(&mut self, impl_id: hir::ItemId, impl_item_id: LocalDefId) -> bool {
if let Some((local_def_id, def_kind)) =
adt_of(self.tcx.hir().item(impl_id).expect_impl().self_ty)
if let TyKind::Path(hir::QPath::Resolved(_, path)) =
self.tcx.hir().item(impl_id).expect_impl().self_ty.kind
&& let Res::Def(def_kind, def_id) = path.res
&& let Some(local_def_id) = def_id.as_local()
&& matches!(def_kind, DefKind::Struct | DefKind::Enum | DefKind::Union)
{
if let Some(trait_item_id) = self.tcx.associated_item(impl_item_id).trait_item_def_id
Expand Down Expand Up @@ -928,7 +916,7 @@ fn create_and_seed_worklist(
match tcx.def_kind(id) {
DefKind::Impl { .. } => false,
DefKind::AssocConst | DefKind::AssocTy | DefKind::AssocFn => !matches!(tcx.associated_item(id).container, AssocItemContainer::ImplContainer),
DefKind::Struct => struct_all_fields_are_public(tcx, id) || has_allow_dead_code_or_lang_attr(tcx, id).is_some(),
DefKind::Struct => struct_all_fields_are_public(tcx, id.to_def_id()) || has_allow_dead_code_or_lang_attr(tcx, id).is_some(),
_ => true
})
.map(|id| (id, ComesFromAllowExpect::No))
Expand Down
45 changes: 0 additions & 45 deletions tests/ui/lint/dead-code/unused-impl-for-non-adts.rs

This file was deleted.

20 changes: 0 additions & 20 deletions tests/ui/lint/dead-code/unused-impl-for-non-adts.stderr

This file was deleted.

0 comments on commit 8a0cd61

Please sign in to comment.