]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/manual_non_exhaustive_enum.rs
Auto merge of #97944 - nikic:freebsd-update, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / manual_non_exhaustive_enum.rs
1 #![warn(clippy::manual_non_exhaustive)]
2 #![allow(unused)]
3
4 enum E {
5     A,
6     B,
7     #[doc(hidden)]
8     _C,
9 }
10
11 // user forgot to remove the marker
12 #[non_exhaustive]
13 enum Ep {
14     A,
15     B,
16     #[doc(hidden)]
17     _C,
18 }
19
20 // marker variant does not have doc hidden attribute, should be ignored
21 enum NoDocHidden {
22     A,
23     B,
24     _C,
25 }
26
27 // name of variant with doc hidden does not start with underscore, should be ignored
28 enum NoUnderscore {
29     A,
30     B,
31     #[doc(hidden)]
32     C,
33 }
34
35 // variant with doc hidden is not unit, should be ignored
36 enum NotUnit {
37     A,
38     B,
39     #[doc(hidden)]
40     _C(bool),
41 }
42
43 // variant with doc hidden is the only one, should be ignored
44 enum OnlyMarker {
45     #[doc(hidden)]
46     _A,
47 }
48
49 // variant with multiple markers, should be ignored
50 enum MultipleMarkers {
51     A,
52     #[doc(hidden)]
53     _B,
54     #[doc(hidden)]
55     _C,
56 }
57
58 // already non_exhaustive and no markers, should be ignored
59 #[non_exhaustive]
60 enum NonExhaustive {
61     A,
62     B,
63 }
64
65 // marked is used, don't lint
66 enum UsedHidden {
67     #[doc(hidden)]
68     _A,
69     B,
70     C,
71 }
72 fn foo(x: &mut UsedHidden) {
73     if matches!(*x, UsedHidden::B) {
74         *x = UsedHidden::_A;
75     }
76 }
77
78 fn main() {}