]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/empty_enum.rs
Rollup merge of #83092 - petrochenkov:qspan, r=estebank
[rust.git] / clippy_lints / src / empty_enum.rs
index 3bfef6f4bed129bc2756dce58b9dca2bc3e7e938..077c3b75fb8c837508fef72290b42571f59715c1 100644 (file)
@@ -8,8 +8,12 @@
 declare_clippy_lint! {
     /// **What it does:** Checks for `enum`s with no variants.
     ///
+    /// As of this writing, the `never_type` is still a
+    /// nightly-only experimental API. Therefore, this lint is only triggered
+    /// if the `never_type` is enabled.
+    ///
     /// **Why is this bad?** If you want to introduce a type which
-    /// can't be instantiated, you should use `!` (the never type),
+    /// can't be instantiated, you should use `!` (the primitive type "never"),
     /// 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.
 
 declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
-    fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) {
-        let did = cx.tcx.hir().local_def_id(item.hir_id);
+impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
+    fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
+        // Only suggest the `never_type` if the feature is enabled
+        if !cx.tcx.features().never_type {
+            return;
+        }
+
         if let ItemKind::Enum(..) = item.kind {
-            let ty = cx.tcx.type_of(did);
+            let ty = cx.tcx.type_of(item.def_id);
             let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
             if adt.variants.is_empty() {
                 span_lint_and_help(