Revert "Rollup merge of #127017 - mu001999-contrib:dead/enhance, r=pnkfelix"
This reverts commita70dc297a8
, reversing changes made toceae37188b
.
This commit is contained in:
parent
361ab1af0c
commit
c6b6c1270a
@ -55,24 +55,7 @@ fn new(ty_is_public: bool, ty_and_all_fields_are_public: bool) -> Self {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn adt_of<'tcx>(ty: &hir::Ty<'tcx>) -> Option<(LocalDefId, DefKind)> {
|
fn struct_all_fields_are_public(tcx: TyCtxt<'_>, id: DefId) -> bool {
|
||||||
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 {
|
|
||||||
// treat PhantomData and positional ZST as public,
|
// treat PhantomData and positional ZST as public,
|
||||||
// we don't want to lint types which only have them,
|
// 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
|
// cause it's a common way to use such types to check things like well-formedness
|
||||||
@ -97,7 +80,10 @@ fn struct_all_fields_are_public(tcx: TyCtxt<'_>, id: LocalDefId) -> bool {
|
|||||||
/// for enum and union, just check they are public,
|
/// for enum and union, just check they are public,
|
||||||
/// and doesn't solve types like &T for now, just skip them
|
/// and doesn't solve types like &T for now, just skip them
|
||||||
fn ty_ref_to_pub_struct(tcx: TyCtxt<'_>, ty: &hir::Ty<'_>) -> Publicness {
|
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 {
|
return match def_kind {
|
||||||
DefKind::Enum | DefKind::Union => {
|
DefKind::Enum | DefKind::Union => {
|
||||||
let ty_is_public = tcx.visibility(def_id).is_public();
|
let ty_is_public = tcx.visibility(def_id).is_public();
|
||||||
@ -580,8 +566,10 @@ fn solve_rest_impl_items(&mut self, mut unsolved_impl_items: Vec<(hir::ItemId, L
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn impl_item_with_used_self(&mut self, impl_id: hir::ItemId, impl_item_id: LocalDefId) -> bool {
|
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)) =
|
if let TyKind::Path(hir::QPath::Resolved(_, path)) =
|
||||||
adt_of(self.tcx.hir().item(impl_id).expect_impl().self_ty)
|
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)
|
&& 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
|
if let Some(trait_item_id) = self.tcx.associated_item(impl_item_id).trait_item_def_id
|
||||||
@ -928,7 +916,7 @@ fn create_and_seed_worklist(
|
|||||||
match tcx.def_kind(id) {
|
match tcx.def_kind(id) {
|
||||||
DefKind::Impl { .. } => false,
|
DefKind::Impl { .. } => false,
|
||||||
DefKind::AssocConst | DefKind::AssocTy | DefKind::AssocFn => !matches!(tcx.associated_item(id).container, AssocItemContainer::ImplContainer),
|
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
|
_ => true
|
||||||
})
|
})
|
||||||
.map(|id| (id, ComesFromAllowExpect::No))
|
.map(|id| (id, ComesFromAllowExpect::No))
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
#![deny(dead_code)]
|
|
||||||
|
|
||||||
struct Foo; //~ ERROR struct `Foo` is never constructed
|
|
||||||
|
|
||||||
trait Trait { //~ ERROR trait `Trait` is never used
|
|
||||||
fn foo(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Trait for Foo {}
|
|
||||||
|
|
||||||
impl Trait for [Foo] {}
|
|
||||||
impl<const N: usize> Trait for [Foo; N] {}
|
|
||||||
|
|
||||||
impl Trait for *const Foo {}
|
|
||||||
impl Trait for *mut Foo {}
|
|
||||||
|
|
||||||
impl Trait for &Foo {}
|
|
||||||
impl Trait for &&Foo {}
|
|
||||||
impl Trait for &mut Foo {}
|
|
||||||
|
|
||||||
impl Trait for [&Foo] {}
|
|
||||||
impl Trait for &[Foo] {}
|
|
||||||
impl Trait for &*const Foo {}
|
|
||||||
|
|
||||||
pub trait Trait2 {
|
|
||||||
fn foo(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Trait2 for Foo {}
|
|
||||||
|
|
||||||
impl Trait2 for [Foo] {}
|
|
||||||
impl<const N: usize> Trait2 for [Foo; N] {}
|
|
||||||
|
|
||||||
impl Trait2 for *const Foo {}
|
|
||||||
impl Trait2 for *mut Foo {}
|
|
||||||
|
|
||||||
impl Trait2 for &Foo {}
|
|
||||||
impl Trait2 for &&Foo {}
|
|
||||||
impl Trait2 for &mut Foo {}
|
|
||||||
|
|
||||||
impl Trait2 for [&Foo] {}
|
|
||||||
impl Trait2 for &[Foo] {}
|
|
||||||
impl Trait2 for &*const Foo {}
|
|
||||||
|
|
||||||
fn main() {}
|
|
@ -1,20 +0,0 @@
|
|||||||
error: struct `Foo` is never constructed
|
|
||||||
--> $DIR/unused-impl-for-non-adts.rs:3:8
|
|
||||||
|
|
|
||||||
LL | struct Foo;
|
|
||||||
| ^^^
|
|
||||||
|
|
|
||||||
note: the lint level is defined here
|
|
||||||
--> $DIR/unused-impl-for-non-adts.rs:1:9
|
|
||||||
|
|
|
||||||
LL | #![deny(dead_code)]
|
|
||||||
| ^^^^^^^^^
|
|
||||||
|
|
||||||
error: trait `Trait` is never used
|
|
||||||
--> $DIR/unused-impl-for-non-adts.rs:5:7
|
|
||||||
|
|
|
||||||
LL | trait Trait {
|
|
||||||
| ^^^^^
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user