]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/manual_non_exhaustive_enum.rs
Rollup merge of #102412 - joboet:dont_panic, r=m-ou-se
[rust.git] / src / tools / clippy / tests / ui / manual_non_exhaustive_enum.rs
1 #![feature(lint_reasons)]
2 #![warn(clippy::manual_non_exhaustive)]
3 #![allow(unused)]
4
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 // marked is used, don't lint
67 enum UsedHidden {
68     #[doc(hidden)]
69     _A,
70     B,
71     C,
72 }
73 fn foo(x: &mut UsedHidden) {
74     if matches!(*x, UsedHidden::B) {
75         *x = UsedHidden::_A;
76     }
77 }
78
79 #[expect(clippy::manual_non_exhaustive)]
80 enum ExpectLint {
81     A,
82     B,
83     #[doc(hidden)]
84     _C,
85 }
86
87 fn main() {}