@@ -55,24 +55,7 @@ impl Publicness {
55
55
}
56
56
}
57
57
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 {
76
59
// treat PhantomData and positional ZST as public,
77
60
// we don't want to lint types which only have them,
78
61
// 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 {
97
80
/// for enum and union, just check they are public,
98
81
/// and doesn't solve types like &T for now, just skip them
99
82
fn 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
+ {
101
87
return match def_kind {
102
88
DefKind :: Enum | DefKind :: Union => {
103
89
let ty_is_public = tcx. visibility ( def_id) . is_public ( ) ;
@@ -580,8 +566,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
580
566
}
581
567
582
568
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 ( )
585
573
&& matches ! ( def_kind, DefKind :: Struct | DefKind :: Enum | DefKind :: Union )
586
574
{
587
575
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(
928
916
match tcx. def_kind ( id) {
929
917
DefKind :: Impl { .. } => false ,
930
918
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 ( ) ,
932
920
_ => true
933
921
} )
934
922
. map ( |id| ( id, ComesFromAllowExpect :: No ) )
0 commit comments