@@ -55,24 +55,24 @@ impl Publicness {
5555}
5656
5757fn struct_all_fields_are_public ( tcx : TyCtxt < ' _ > , id : DefId ) -> bool {
58- // treat PhantomData and positional ZST as public,
59- // we don't want to lint types which only have them,
60- // cause it's a common way to use such types to check things like well-formedness
61- tcx. adt_def ( id) . all_fields ( ) . all ( |field| {
58+ // skip types contain fields of unit and never type,
59+ // it's usually intentional to make the type not constructible
60+ let not_require_constructor = tcx. adt_def ( id) . all_fields ( ) . any ( |field| {
6261 let field_type = tcx. type_of ( field. did ) . instantiate_identity ( ) ;
63- if field_type. is_phantom_data ( ) {
64- return true ;
65- }
66- let is_positional = field. name . as_str ( ) . starts_with ( |c : char | c. is_ascii_digit ( ) ) ;
67- if is_positional
68- && tcx
69- . layout_of ( tcx. param_env ( field. did ) . and ( field_type) )
70- . map_or ( true , |layout| layout. is_zst ( ) )
71- {
72- return true ;
73- }
74- field. vis . is_public ( )
75- } )
62+ field_type. is_unit ( ) || field_type. is_never ( )
63+ } ) ;
64+
65+ not_require_constructor
66+ || tcx. adt_def ( id) . all_fields ( ) . all ( |field| {
67+ let field_type = tcx. type_of ( field. did ) . instantiate_identity ( ) ;
68+ // skip fields of PhantomData,
69+ // cause it's a common way to check things like well-formedness
70+ if field_type. is_phantom_data ( ) {
71+ return true ;
72+ }
73+
74+ field. vis . is_public ( )
75+ } )
7676}
7777
7878/// check struct and its fields are public or not,
0 commit comments