Fixes internal lint warning in code base.

This commit is contained in:
xiongmao86
2020-04-17 22:01:25 +08:00
parent bdd32e7700
commit d03d3bd95b
9 changed files with 153 additions and 151 deletions

View File

@@ -1,6 +1,6 @@
//! lint when there is an enum with no variants
use crate::utils::span_lint_and_then;
use crate::utils::span_lint_and_help;
use rustc_hir::{Item, ItemKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -45,13 +45,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
let ty = cx.tcx.type_of(did);
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
if adt.variants.is_empty() {
span_lint_and_then(cx, EMPTY_ENUM, item.span, "enum with no variants", |diag| {
diag.span_help(
item.span,
"consider using the uninhabited type `!` (never type) or a wrapper \
around it to introduce a type which can't be instantiated",
);
});
span_lint_and_then(
cx,
EMPTY_ENUM,
item.span,
"enum with no variants",
"consider using the uninhabited type `!` (never type) or a wrapper around it \
to introduce a type which can't be instantiated",
);
}
}
}