@@ -70,20 +70,24 @@ declare_lint_pass!(ExhaustiveItems => [EXHAUSTIVE_ENUMS, EXHAUSTIVE_STRUCTS]);
70
70
71
71
impl LateLintPass < ' _ > for ExhaustiveItems {
72
72
fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & Item < ' _ > ) {
73
- if let ItemKind :: Enum ( ..) | ItemKind :: Struct ( ..) = item. kind
74
- && cx. effective_visibilities . is_exported ( item. owner_id . def_id )
73
+ let ( lint, msg, fields) = match item. kind {
74
+ ItemKind :: Enum ( ..) => (
75
+ EXHAUSTIVE_ENUMS ,
76
+ "exported enums should not be exhaustive" ,
77
+ [ ] . as_slice ( ) ,
78
+ ) ,
79
+ ItemKind :: Struct ( v, ..) => (
80
+ EXHAUSTIVE_STRUCTS ,
81
+ "exported structs should not be exhaustive" ,
82
+ v. fields ( ) ,
83
+ ) ,
84
+ _ => return ,
85
+ } ;
86
+ if cx. effective_visibilities . is_exported ( item. owner_id . def_id )
75
87
&& let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) )
76
88
&& !attrs. iter ( ) . any ( |a| a. has_name ( sym:: non_exhaustive) )
89
+ && fields. iter ( ) . all ( |f| cx. tcx . visibility ( f. def_id ) . is_public ( ) )
77
90
{
78
- let ( lint, msg) = if let ItemKind :: Struct ( ref v, ..) = item. kind {
79
- if v. fields ( ) . iter ( ) . any ( |f| !cx. tcx . visibility ( f. def_id ) . is_public ( ) ) {
80
- // skip structs with private fields
81
- return ;
82
- }
83
- ( EXHAUSTIVE_STRUCTS , "exported structs should not be exhaustive" )
84
- } else {
85
- ( EXHAUSTIVE_ENUMS , "exported enums should not be exhaustive" )
86
- } ;
87
91
let suggestion_span = item. span . shrink_to_lo ( ) ;
88
92
let indent = " " . repeat ( indent_of ( cx, item. span ) . unwrap_or ( 0 ) ) ;
89
93
span_lint_and_then ( cx, lint, item. span , msg, |diag| {
0 commit comments