1 //! lint when there is an enum with no variants
5 use crate::utils::span_lint_and_then;
7 /// **What it does:** Checks for `enum`s with no variants.
9 /// **Why is this bad?** Enum's with no variants should be replaced with `!`,
10 /// the uninhabited type,
11 /// or a wrapper around it.
13 /// **Known problems:** None.
19 declare_clippy_lint! {
22 "enum with no variants"
25 #[derive(Copy, Clone)]
28 impl LintPass for EmptyEnum {
29 fn get_lints(&self) -> LintArray {
30 lint_array!(EMPTY_ENUM)
34 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
35 fn check_item(&mut self, cx: &LateContext, item: &Item) {
36 let did = cx.tcx.hir.local_def_id(item.id);
37 if let ItemEnum(..) = item.node {
38 let ty = cx.tcx.type_of(did);
39 let adt = ty.ty_adt_def()
40 .expect("already checked whether this is an enum");
41 if adt.variants.is_empty() {
42 span_lint_and_then(cx, EMPTY_ENUM, item.span, "enum with no variants", |db| {
43 db.span_help(item.span, "consider using the uninhabited type `!` or a wrapper around it");