This commit is contained in:
Oliver Schneider
2017-08-09 09:30:56 +02:00
parent 705c6ec2a4
commit b25b6b3355
95 changed files with 3090 additions and 2022 deletions

View File

@@ -6,7 +6,8 @@ use utils::span_lint_and_then;
/// **What it does:** Checks for `enum`s with no variants.
///
/// **Why is this bad?** Enum's with no variants should be replaced with `!`, the uninhabited type,
/// **Why is this bad?** Enum's with no variants should be replaced with `!`,
/// the uninhabited type,
/// or a wrapper around it.
///
/// **Known problems:** None.
@@ -21,7 +22,7 @@ declare_lint! {
"enum with no variants"
}
#[derive(Copy,Clone)]
#[derive(Copy, Clone)]
pub struct EmptyEnum;
impl LintPass for EmptyEnum {
@@ -35,7 +36,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
let did = cx.tcx.hir.local_def_id(item.id);
if let ItemEnum(..) = item.node {
let ty = cx.tcx.type_of(did);
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
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", |db| {
db.span_help(item.span, "consider using the uninhabited type `!` or a wrapper around it");