@@ -73,26 +73,22 @@ fn adt_of<'tcx>(ty: &hir::Ty<'tcx>) -> Option<(LocalDefId, DefKind)> {
7373}
7474
7575fn struct_all_fields_are_public ( tcx : TyCtxt < ' _ > , id : LocalDefId ) -> bool {
76- let adt_def = tcx. adt_def ( id) ;
77-
78- // skip types contain fields of unit and never type,
79- // it's usually intentional to make the type not constructible
80- let not_require_constructor = adt_def. all_fields ( ) . any ( |field| {
76+ for field in tcx. adt_def ( id) . all_fields ( ) {
8177 let field_type = tcx. type_of ( field. did ) . instantiate_identity ( ) ;
82- field_type. is_unit ( ) || field_type. is_never ( )
83- } ) ;
84-
85- not_require_constructor
86- || adt_def. all_fields ( ) . all ( |field| {
87- let field_type = tcx. type_of ( field. did ) . instantiate_identity ( ) ;
88- // skip fields of PhantomData,
89- // cause it's a common way to check things like well-formedness
90- if field_type. is_phantom_data ( ) {
91- return true ;
92- }
9378
94- field. vis . is_public ( )
95- } )
79+ // skip types contain fields of unit and never type,
80+ // it's usually intentional to make the type not constructible
81+ if field_type. is_unit ( ) || field_type. is_never ( ) {
82+ return true ;
83+ }
84+
85+ // skip fields of PhantomData,
86+ // cause it's a common way to check things like well-formedness
87+ if !field_type. is_phantom_data ( ) && !field. vis . is_public ( ) {
88+ return false ;
89+ }
90+ }
91+ true
9692}
9793
9894/// check struct and its fields are public or not,
0 commit comments