Skip to content

improve empty_enum documentation #5087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions clippy_lints/src/empty_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,29 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
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"
Expand All @@ -35,7 +48,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
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",
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/empty_enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down