This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree 4 files changed +41
-19
lines changed 4 files changed +41
-19
lines changed Original file line number Diff line number Diff line change @@ -75,10 +75,14 @@ impl LateLintPass<'_> for ExhaustiveItems {
75
75
if cx. access_levels. is_exported( item. hir_id) ;
76
76
if !item. attrs. iter( ) . any( |a| a. has_name( sym:: non_exhaustive) ) ;
77
77
then {
78
- let ( lint, msg) = if let ItemKind :: Enum ( ..) = item. kind {
79
- ( EXHAUSTIVE_ENUMS , "exported enums should not be exhaustive" )
80
- } else {
78
+ let ( lint, msg) = if let ItemKind :: Struct ( ref v, ..) = item. kind {
79
+ if v. fields( ) . iter( ) . any( |f| !f. vis. node. is_pub( ) ) {
80
+ // skip structs with private fields
81
+ return ;
82
+ }
81
83
( EXHAUSTIVE_STRUCTS , "exported structs should not be exhaustive" )
84
+ } else {
85
+ ( EXHAUSTIVE_ENUMS , "exported enums should not be exhaustive" )
82
86
} ;
83
87
let suggestion_span = item. span. shrink_to_lo( ) ;
84
88
let indent = " " . repeat( indent_of( cx, item. span) . unwrap_or( 0 ) ) ;
Original file line number Diff line number Diff line change @@ -56,27 +56,36 @@ pub mod enums {
56
56
pub mod structs {
57
57
#[non_exhaustive]
58
58
pub struct Exhaustive {
59
- foo: u8,
60
- bar: String,
59
+ pub foo: u8,
60
+ pub bar: String,
61
61
}
62
62
63
63
// no warning, already non_exhaustive
64
64
#[non_exhaustive]
65
65
pub struct NonExhaustive {
66
- foo: u8,
66
+ pub foo: u8,
67
+ pub bar: String,
68
+ }
69
+
70
+ // no warning, private fields
71
+ pub struct ExhaustivePrivateFieldTuple(u8);
72
+
73
+ // no warning, private fields
74
+ pub struct ExhaustivePrivateField {
75
+ pub foo: u8,
67
76
bar: String,
68
77
}
69
78
70
79
// no warning, private
71
80
struct ExhaustivePrivate {
72
- foo: u8,
73
- bar: String,
81
+ pub foo: u8,
82
+ pub bar: String,
74
83
}
75
84
76
85
// no warning, private
77
86
#[non_exhaustive]
78
87
struct NonExhaustivePrivate {
79
- foo: u8,
80
- bar: String,
88
+ pub foo: u8,
89
+ pub bar: String,
81
90
}
82
91
}
Original file line number Diff line number Diff line change @@ -53,27 +53,36 @@ pub mod enums {
53
53
54
54
pub mod structs {
55
55
pub struct Exhaustive {
56
- foo : u8 ,
57
- bar : String ,
56
+ pub foo : u8 ,
57
+ pub bar : String ,
58
58
}
59
59
60
60
// no warning, already non_exhaustive
61
61
#[ non_exhaustive]
62
62
pub struct NonExhaustive {
63
- foo : u8 ,
63
+ pub foo : u8 ,
64
+ pub bar : String ,
65
+ }
66
+
67
+ // no warning, private fields
68
+ pub struct ExhaustivePrivateFieldTuple ( u8 ) ;
69
+
70
+ // no warning, private fields
71
+ pub struct ExhaustivePrivateField {
72
+ pub foo : u8 ,
64
73
bar : String ,
65
74
}
66
75
67
76
// no warning, private
68
77
struct ExhaustivePrivate {
69
- foo : u8 ,
70
- bar : String ,
78
+ pub foo : u8 ,
79
+ pub bar : String ,
71
80
}
72
81
73
82
// no warning, private
74
83
#[ non_exhaustive]
75
84
struct NonExhaustivePrivate {
76
- foo : u8 ,
77
- bar : String ,
85
+ pub foo : u8 ,
86
+ pub bar : String ,
78
87
}
79
88
}
Original file line number Diff line number Diff line change @@ -41,8 +41,8 @@ error: exported structs should not be exhaustive
41
41
--> $DIR/exhaustive_items.rs:55:5
42
42
|
43
43
LL | / pub struct Exhaustive {
44
- LL | | foo: u8,
45
- LL | | bar: String,
44
+ LL | | pub foo: u8,
45
+ LL | | pub bar: String,
46
46
LL | | }
47
47
| |_____^
48
48
|
You can’t perform that action at this time.
0 commit comments