]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/manual_non_exhaustive.txt
:arrow_up: rust-analyzer
[rust.git] / src / tools / clippy / src / docs / manual_non_exhaustive.txt
1 ### What it does
2 Checks for manual implementations of the non-exhaustive pattern.
3
4 ### Why is this bad?
5 Using the #[non_exhaustive] attribute expresses better the intent
6 and allows possible optimizations when applied to enums.
7
8 ### Example
9 ```
10 struct S {
11     pub a: i32,
12     pub b: i32,
13     _c: (),
14 }
15
16 enum E {
17     A,
18     B,
19     #[doc(hidden)]
20     _C,
21 }
22
23 struct T(pub i32, pub i32, ());
24 ```
25 Use instead:
26 ```
27 #[non_exhaustive]
28 struct S {
29     pub a: i32,
30     pub b: i32,
31 }
32
33 #[non_exhaustive]
34 enum E {
35     A,
36     B,
37 }
38
39 #[non_exhaustive]
40 struct T(pub i32, pub i32);
41 ```