@@ -55,24 +55,7 @@ impl Publicness {
5555 }
5656}
5757
58- fn adt_of < ' tcx > ( ty : & hir:: Ty < ' tcx > ) -> Option < ( LocalDefId , DefKind ) > {
59- match ty. kind {
60- TyKind :: Path ( hir:: QPath :: Resolved ( _, path) ) => {
61- if let Res :: Def ( def_kind, def_id) = path. res
62- && let Some ( local_def_id) = def_id. as_local ( )
63- {
64- Some ( ( local_def_id, def_kind) )
65- } else {
66- None
67- }
68- }
69- TyKind :: Slice ( ty) | TyKind :: Array ( ty, _) => adt_of ( ty) ,
70- TyKind :: Ptr ( ty) | TyKind :: Ref ( _, ty) => adt_of ( ty. ty ) ,
71- _ => None ,
72- }
73- }
74-
75- fn struct_all_fields_are_public ( tcx : TyCtxt < ' _ > , id : LocalDefId ) -> bool {
58+ fn struct_all_fields_are_public ( tcx : TyCtxt < ' _ > , id : DefId ) -> bool {
7659 // treat PhantomData and positional ZST as public,
7760 // we don't want to lint types which only have them,
7861 // 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 {
9780/// for enum and union, just check they are public,
9881/// and doesn't solve types like &T for now, just skip them
9982fn ty_ref_to_pub_struct ( tcx : TyCtxt < ' _ > , ty : & hir:: Ty < ' _ > ) -> Publicness {
100- if let Some ( ( def_id, def_kind) ) = adt_of ( ty) {
83+ if let TyKind :: Path ( hir:: QPath :: Resolved ( _, path) ) = ty. kind
84+ && let Res :: Def ( def_kind, def_id) = path. res
85+ && def_id. is_local ( )
86+ {
10187 return match def_kind {
10288 DefKind :: Enum | DefKind :: Union => {
10389 let ty_is_public = tcx. visibility ( def_id) . is_public ( ) ;
@@ -580,8 +566,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
580566 }
581567
582568 fn impl_item_with_used_self ( & mut self , impl_id : hir:: ItemId , impl_item_id : LocalDefId ) -> bool {
583- if let Some ( ( local_def_id, def_kind) ) =
584- adt_of ( self . tcx . hir ( ) . item ( impl_id) . expect_impl ( ) . self_ty )
569+ if let TyKind :: Path ( hir:: QPath :: Resolved ( _, path) ) =
570+ self . tcx . hir ( ) . item ( impl_id) . expect_impl ( ) . self_ty . kind
571+ && let Res :: Def ( def_kind, def_id) = path. res
572+ && let Some ( local_def_id) = def_id. as_local ( )
585573 && matches ! ( def_kind, DefKind :: Struct | DefKind :: Enum | DefKind :: Union )
586574 {
587575 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(
928916 match tcx. def_kind ( id) {
929917 DefKind :: Impl { .. } => false ,
930918 DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: AssocFn => !matches ! ( tcx. associated_item( id) . container, AssocItemContainer :: ImplContainer ) ,
931- DefKind :: Struct => struct_all_fields_are_public ( tcx, id) || has_allow_dead_code_or_lang_attr ( tcx, id) . is_some ( ) ,
919+ DefKind :: Struct => struct_all_fields_are_public ( tcx, id. to_def_id ( ) ) || has_allow_dead_code_or_lang_attr ( tcx, id) . is_some ( ) ,
932920 _ => true
933921 } )
934922 . map ( |id| ( id, ComesFromAllowExpect :: No ) )
0 commit comments