1 //! lint when there is an enum with no variants
3 use crate::utils::span_lint_and_then;
4 use rustc::declare_lint_pass;
6 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
7 use rustc_session::declare_tool_lint;
10 /// **What it does:** Checks for `enum`s with no variants.
12 /// **Why is this bad?** Enum's with no variants should be replaced with `!`,
13 /// the uninhabited type,
14 /// or a wrapper around it.
16 /// **Known problems:** None.
24 "enum with no variants"
27 declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
29 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
30 fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
31 let did = cx.tcx.hir().local_def_id(item.hir_id);
32 if let ItemKind::Enum(..) = item.kind {
33 let ty = cx.tcx.type_of(did);
34 let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
35 if adt.variants.is_empty() {
36 span_lint_and_then(cx, EMPTY_ENUM, item.span, "enum with no variants", |db| {
39 "consider using the uninhabited type `!` or a wrapper around it",