Rollup merge of #127017 - mu001999-contrib:dead/enhance, r=pnkfelix · compiler-errors/rust@a70dc29 (original) (raw)
`@@ -54,7 +54,24 @@ impl Publicness {
`
54
54
`}
`
55
55
`}
`
56
56
``
57
``
`-
fn struct_all_fields_are_public(tcx: TyCtxt<'_>, id: DefId) -> bool {
`
``
57
`+
fn adt_of<'tcx>(ty: &hir::Ty<'tcx>) -> Option<(LocalDefId, DefKind)> {
`
``
58
`+
match ty.kind {
`
``
59
`+
TyKind::Path(hir::QPath::Resolved(_, path)) => {
`
``
60
`+
if let Res::Def(def_kind, def_id) = path.res
`
``
61
`+
&& let Some(local_def_id) = def_id.as_local()
`
``
62
`+
{
`
``
63
`+
Some((local_def_id, def_kind))
`
``
64
`+
} else {
`
``
65
`+
None
`
``
66
`+
}
`
``
67
`+
}
`
``
68
`+
TyKind::Slice(ty) | TyKind::Array(ty, _) => adt_of(ty),
`
``
69
`+
TyKind::Ptr(ty) | TyKind::Ref(_, ty) => adt_of(ty.ty),
`
``
70
`+
_ => None,
`
``
71
`+
}
`
``
72
`+
}
`
``
73
+
``
74
`+
fn struct_all_fields_are_public(tcx: TyCtxt<'_>, id: LocalDefId) -> bool {
`
58
75
`// treat PhantomData and positional ZST as public,
`
59
76
`// we don't want to lint types which only have them,
`
60
77
`// cause it's a common way to use such types to check things like well-formedness
`
`@@ -79,10 +96,7 @@ fn struct_all_fields_are_public(tcx: TyCtxt<'_>, id: DefId) -> bool {
`
79
96
`/// for enum and union, just check they are public,
`
80
97
`/// and doesn't solve types like &T for now, just skip them
`
81
98
`fn ty_ref_to_pub_struct(tcx: TyCtxt<'_>, ty: &hir::Ty<'_>) -> Publicness {
`
82
``
`-
if let TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind
`
83
``
`-
&& let Res::Def(def_kind, def_id) = path.res
`
84
``
`-
&& def_id.is_local()
`
85
``
`-
{
`
``
99
`+
if let Some((def_id, def_kind)) = adt_of(ty) {
`
86
100
`return match def_kind {
`
87
101
`DefKind::Enum | DefKind::Union => {
`
88
102
`let ty_is_public = tcx.visibility(def_id).is_public();
`
`@@ -565,10 +579,8 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
`
565
579
`}
`
566
580
``
567
581
`fn impl_item_with_used_self(&mut self, impl_id: hir::ItemId, impl_item_id: LocalDefId) -> bool {
`
568
``
`-
if let TyKind::Path(hir::QPath::Resolved(_, path)) =
`
569
``
`-
self.tcx.hir().item(impl_id).expect_impl().self_ty.kind
`
570
``
`-
&& let Res::Def(def_kind, def_id) = path.res
`
571
``
`-
&& let Some(local_def_id) = def_id.as_local()
`
``
582
`+
if let Some((local_def_id, def_kind)) =
`
``
583
`+
adt_of(self.tcx.hir().item(impl_id).expect_impl().self_ty)
`
572
584
` && matches!(def_kind, DefKind::Struct | DefKind::Enum | DefKind::Union)
`
573
585
`{
`
574
586
`if let Some(trait_item_id) = self.tcx.associated_item(impl_item_id).trait_item_def_id
`
`@@ -915,7 +927,7 @@ fn create_and_seed_worklist(
`
915
927
`match tcx.def_kind(id) {
`
916
928
`DefKind::Impl { .. } => false,
`
917
929
`DefKind::AssocConst | DefKind::AssocTy | DefKind::AssocFn => !matches!(tcx.associated_item(id).container, AssocItemContainer::ImplContainer),
`
918
``
`-
DefKind::Struct => struct_all_fields_are_public(tcx, id.to_def_id()) || has_allow_dead_code_or_lang_attr(tcx, id).is_some(),
`
``
930
`+
DefKind::Struct => struct_all_fields_are_public(tcx, id) || has_allow_dead_code_or_lang_attr(tcx, id).is_some(),
`
919
931
` _ => true
`
920
932
`})
`
921
933
`.map(|id| (id, ComesFromAllowExpect::No))
`