Skip to content

Commit bc97f5d

Browse files
committed
Address flip1995's review comments
1 parent 275988c commit bc97f5d

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

clippy_lints/src/empty_enum.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ 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-
/// As of this writing, the never type is still a
11+
/// As of this writing, the `never_type` is still a
1212
/// nightly-only experimental API. Therefore, this lint is only triggered
13-
/// if the never type is enabled
13+
/// if the `never_type` is enabled.
1414
///
1515
/// **Why is this bad?** If you want to introduce a type which
16-
/// can't be instantiated, you should use `!` (the never type),
16+
/// can't be instantiated, you should use `!` (the primitive type never),
1717
/// or a wrapper around it, because `!` has more extensive
1818
/// compiler support (type inference, etc...) and wrappers
1919
/// around it are the conventional way to define an uninhabited type.
@@ -44,13 +44,16 @@ declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
4444

4545
impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
4646
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
47+
// Only suggest the `never_type` if the feature is enabled
48+
if !cx.tcx.features().never_type {
49+
return;
50+
}
51+
4752
let did = cx.tcx.hir().local_def_id(item.hir_id);
4853
if let ItemKind::Enum(..) = item.kind {
4954
let ty = cx.tcx.type_of(did);
5055
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
51-
52-
// Only suggest the never type if the feature is enabled
53-
if adt.variants.is_empty() && cx.tcx.features().never_type {
56+
if adt.variants.is_empty() {
5457
span_lint_and_help(
5558
cx,
5659
EMPTY_ENUM,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![allow(dead_code)]
2+
#![warn(clippy::empty_enum)]
3+
4+
// `never_type` is not enabled; this test has no stderr file
5+
enum Empty {}
6+
7+
fn main() {}

0 commit comments

Comments
 (0)