]> git.lizzy.rs Git - rust.git/commitdiff
improve empty_enum documentation
authorMikhail Babenko <misha-babenko@yandex.ru>
Fri, 24 Jan 2020 11:37:16 +0000 (14:37 +0300)
committerMikhail Babenko <misha-babenko@yandex.ru>
Fri, 24 Jan 2020 11:37:16 +0000 (14:37 +0300)
clippy_lints/src/empty_enum.rs
tests/ui/empty_enum.stderr

index 0a8d9977845e8b96c611368c7c31fd04231f5132..c43db68d20f24e1ad19943d9e3fec04e151ff97d 100644 (file)
@@ -8,16 +8,29 @@
 declare_clippy_lint! {
     /// **What it does:** Checks for `enum`s with no variants.
     ///
-    /// **Why is this bad?** Enum's with no variants should be replaced with `!`,
-    /// the uninhabited type,
-    /// or a wrapper around it.
+    /// **Why is this bad?** If you want to introduce a type which
+    /// can't be instantiated, you should use `!` (the never type),
+    /// or a wrapper around it, because `!` has more extensive
+    /// compiler support (type inference, etc...) and wrappers
+    /// around it are the conventional way to define an uninhabited type.
+    /// For further information visit [never type documentation](https://doc.rust-lang.org/std/primitive.never.html)
+    ///
     ///
     /// **Known problems:** None.
     ///
     /// **Example:**
+    ///
+    /// Bad:
     /// ```rust
     /// enum Test {}
     /// ```
+    ///
+    /// Good:
+    /// ```rust
+    /// #![feature(never_type)]
+    ///
+    /// struct Test(!);
+    /// ```
     pub EMPTY_ENUM,
     pedantic,
     "enum with no variants"
@@ -35,7 +48,8 @@ fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) {
                 span_lint_and_then(cx, EMPTY_ENUM, item.span, "enum with no variants", |db| {
                     db.span_help(
                         item.span,
-                        "consider using the uninhabited type `!` or a wrapper around it",
+                        "consider using the uninhabited type `!` (never type) or a wrapper \
+                         around it to introduce a type which can't be instantiated",
                     );
                 });
             }
index 223a14ed8772693961f506e75000ffdea65bf30e..b1e4eb277550aa3d81942bb7d35613d935f8df40 100644 (file)
@@ -5,7 +5,7 @@ LL | enum Empty {}
    | ^^^^^^^^^^^^^
    |
    = note: `-D clippy::empty-enum` implied by `-D warnings`
-help: consider using the uninhabited type `!` or a wrapper around it
+help: consider using the uninhabited type `!` (never type) or a wrapper around it to introduce a type which can't be instantiated
   --> $DIR/empty_enum.rs:4:1
    |
 LL | enum Empty {}