Skip to content

Commit 199ae17

Browse files
committed
improve empty_enum documentation
1 parent 2c7cfa8 commit 199ae17

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

clippy_lints/src/empty_enum.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,29 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
88
declare_clippy_lint! {
99
/// **What it does:** Checks for `enum`s with no variants.
1010
///
11-
/// **Why is this bad?** Enum's with no variants should be replaced with `!`,
12-
/// the uninhabited type,
13-
/// or a wrapper around it.
11+
/// **Why is this bad?** If you want to introduce a type which
12+
/// can't be instantiated, you should use `!` (the never type),
13+
/// or a wrapper around it, because `!` has more extensive
14+
/// compiler support (type inference, etc...) and wrappers
15+
/// around it are the conventional way to define an uninhabited type.
16+
/// For further information visit [never type documentation](https://doc.rust-lang.org/std/primitive.never.html)
17+
///
1418
///
1519
/// **Known problems:** None.
1620
///
1721
/// **Example:**
22+
///
23+
/// Bad:
1824
/// ```rust
1925
/// enum Test {}
2026
/// ```
27+
///
28+
/// Good:
29+
/// ```rust
30+
/// #![feature(never_type)]
31+
///
32+
/// struct Test(!);
33+
/// ```
2134
pub EMPTY_ENUM,
2235
pedantic,
2336
"enum with no variants"
@@ -35,7 +48,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
3548
span_lint_and_then(cx, EMPTY_ENUM, item.span, "enum with no variants", |db| {
3649
db.span_help(
3750
item.span,
38-
"consider using the uninhabited type `!` or a wrapper around it",
51+
"consider using the uninhabited type `!` (never type) or a wrapper \
52+
around it to introduce a type which can't be instantiated",
3953
);
4054
});
4155
}

tests/ui/empty_enum.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | enum Empty {}
55
| ^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::empty-enum` implied by `-D warnings`
8-
help: consider using the uninhabited type `!` or a wrapper around it
8+
help: consider using the uninhabited type `!` (never type) or a wrapper around it to introduce a type which can't be instantiated
99
--> $DIR/empty_enum.rs:4:1
1010
|
1111
LL | enum Empty {}

0 commit comments

Comments
 (0)