@@ -8,12 +8,12 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
8
8
declare_clippy_lint ! {
9
9
/// **What it does:** Checks for `enum`s with no variants.
10
10
///
11
- /// As of this writing, the never type is still a
11
+ /// As of this writing, the `never_type` is still a
12
12
/// nightly-only experimental API. Therefore, this lint is only triggered
13
- /// if the never type is enabled
13
+ /// if the `never_type` is enabled.
14
14
///
15
15
/// **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 ),
17
17
/// or a wrapper around it, because `!` has more extensive
18
18
/// compiler support (type inference, etc...) and wrappers
19
19
/// around it are the conventional way to define an uninhabited type.
@@ -44,13 +44,16 @@ declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
44
44
45
45
impl < ' tcx > LateLintPass < ' tcx > for EmptyEnum {
46
46
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
+
47
52
let did = cx. tcx . hir ( ) . local_def_id ( item. hir_id ) ;
48
53
if let ItemKind :: Enum ( ..) = item. kind {
49
54
let ty = cx. tcx . type_of ( did) ;
50
55
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 ( ) {
54
57
span_lint_and_help (
55
58
cx,
56
59
EMPTY_ENUM ,
0 commit comments