summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/manual_non_exhaustive.txt
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/src/docs/manual_non_exhaustive.txt')
-rw-r--r--src/tools/clippy/src/docs/manual_non_exhaustive.txt41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/manual_non_exhaustive.txt b/src/tools/clippy/src/docs/manual_non_exhaustive.txt
new file mode 100644
index 000000000..fb021393b
--- /dev/null
+++ b/src/tools/clippy/src/docs/manual_non_exhaustive.txt
@@ -0,0 +1,41 @@
+### What it does
+Checks for manual implementations of the non-exhaustive pattern.
+
+### Why is this bad?
+Using the #[non_exhaustive] attribute expresses better the intent
+and allows possible optimizations when applied to enums.
+
+### Example
+```
+struct S {
+ pub a: i32,
+ pub b: i32,
+ _c: (),
+}
+
+enum E {
+ A,
+ B,
+ #[doc(hidden)]
+ _C,
+}
+
+struct T(pub i32, pub i32, ());
+```
+Use instead:
+```
+#[non_exhaustive]
+struct S {
+ pub a: i32,
+ pub b: i32,
+}
+
+#[non_exhaustive]
+enum E {
+ A,
+ B,
+}
+
+#[non_exhaustive]
+struct T(pub i32, pub i32);
+``` \ No newline at end of file