1 //! lint when there is an enum with no variants
5 use 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 `!`, the uninhabited type,
10 /// or a wrapper around it.
12 /// **Known problems:** None.
21 "enum with no variants"
27 impl LintPass for EmptyEnum {
28 fn get_lints(&self) -> LintArray {
29 lint_array!(EMPTY_ENUM)
33 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
34 fn check_item(&mut self, cx: &LateContext, item: &Item) {
35 let did = cx.tcx.hir.local_def_id(item.id);
36 if let ItemEnum(..) = item.node {
37 let ty = cx.tcx.item_type(did);
38 let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
39 if adt.variants.is_empty() {
40 span_lint_and_then(cx, EMPTY_ENUM, item.span, "enum with no variants", |db| {
41 db.span_help(item.span, "consider using the uninhabited type `!` or a wrapper around it");