]> git.lizzy.rs Git - rust.git/blob - tests/ui/manual_non_exhaustive.rs
iterate List by value
[rust.git] / tests / ui / manual_non_exhaustive.rs
1 #![warn(clippy::manual_non_exhaustive)]
2 #![allow(unused)]
3
4 mod enums {
5     enum E {
6         A,
7         B,
8         #[doc(hidden)]
9         _C,
10     }
11
12     // user forgot to remove the marker
13     #[non_exhaustive]
14     enum Ep {
15         A,
16         B,
17         #[doc(hidden)]
18         _C,
19     }
20
21     // marker variant does not have doc hidden attribute, should be ignored
22     enum NoDocHidden {
23         A,
24         B,
25         _C,
26     }
27
28     // name of variant with doc hidden does not start with underscore, should be ignored
29     enum NoUnderscore {
30         A,
31         B,
32         #[doc(hidden)]
33         C,
34     }
35
36     // variant with doc hidden is not unit, should be ignored
37     enum NotUnit {
38         A,
39         B,
40         #[doc(hidden)]
41         _C(bool),
42     }
43
44     // variant with doc hidden is the only one, should be ignored
45     enum OnlyMarker {
46         #[doc(hidden)]
47         _A,
48     }
49
50     // variant with multiple markers, should be ignored
51     enum MultipleMarkers {
52         A,
53         #[doc(hidden)]
54         _B,
55         #[doc(hidden)]
56         _C,
57     }
58
59     // already non_exhaustive and no markers, should be ignored
60     #[non_exhaustive]
61     enum NonExhaustive {
62         A,
63         B,
64     }
65 }
66
67 mod structs {
68     struct S {
69         pub a: i32,
70         pub b: i32,
71         _c: (),
72     }
73
74     // user forgot to remove the private field
75     #[non_exhaustive]
76     struct Sp {
77         pub a: i32,
78         pub b: i32,
79         _c: (),
80     }
81
82     // some other fields are private, should be ignored
83     struct PrivateFields {
84         a: i32,
85         pub b: i32,
86         _c: (),
87     }
88
89     // private field name does not start with underscore, should be ignored
90     struct NoUnderscore {
91         pub a: i32,
92         pub b: i32,
93         c: (),
94     }
95
96     // private field is not unit type, should be ignored
97     struct NotUnit {
98         pub a: i32,
99         pub b: i32,
100         _c: i32,
101     }
102
103     // private field is the only field, should be ignored
104     struct OnlyMarker {
105         _a: (),
106     }
107
108     // already non exhaustive and no private fields, should be ignored
109     #[non_exhaustive]
110     struct NonExhaustive {
111         pub a: i32,
112         pub b: i32,
113     }
114 }
115
116 mod tuple_structs {
117     struct T(pub i32, pub i32, ());
118
119     // user forgot to remove the private field
120     #[non_exhaustive]
121     struct Tp(pub i32, pub i32, ());
122
123     // some other fields are private, should be ignored
124     struct PrivateFields(pub i32, i32, ());
125
126     // private field is not unit type, should be ignored
127     struct NotUnit(pub i32, pub i32, i32);
128
129     // private field is the only field, should be ignored
130     struct OnlyMarker(());
131
132     // already non exhaustive and no private fields, should be ignored
133     #[non_exhaustive]
134     struct NonExhaustive(pub i32, pub i32);
135 }
136
137 fn main() {}