Tweak error on empty match

This commit is contained in:
Nadrieril 2019-11-30 16:27:58 +00:00
parent b26aa0b529
commit 1bd97ae8a1
3 changed files with 8 additions and 9 deletions

View file

@ -180,11 +180,8 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
ty::Never => true,
ty::Adt(def, _) => {
def_span = self.tcx.hir().span_if_local(def.did);
if def.variants.len() < 4 && !def.variants.is_empty() {
// keep around to point at the definition of non-covered variants
missing_variants =
def.variants.iter().map(|variant| variant.ident).collect();
}
missing_variants =
def.variants.iter().map(|variant| variant.ident).collect();
def.variants.is_empty() && !cx.is_foreign_non_exhaustive_enum(pat_ty)
}
@ -219,8 +216,10 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
err.span_label(sp, format!("`{}` defined here", pat_ty));
}
// point at the definition of non-covered enum variants
for variant in &missing_variants {
err.span_label(variant.span, "variant not covered");
if missing_variants.len() < 4 {
for variant in &missing_variants {
err.span_label(variant.span, "variant not covered");
}
}
err.emit();
}

View file

@ -44,5 +44,5 @@ fn main() {
match NonEmptyEnum2::Foo(true) {}
//~^ ERROR multiple patterns of type `NonEmptyEnum2` are not handled
match NonEmptyEnum5::V1 {}
//~^ ERROR type `NonEmptyEnum5` is non-empty
//~^ ERROR multiple patterns of type `NonEmptyEnum5` are not handled
}

View file

@ -50,7 +50,7 @@ LL | match NonEmptyEnum2::Foo(true) {}
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: type `NonEmptyEnum5` is non-empty
error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum5` are not handled
--> $DIR/match-empty.rs:46:11
|
LL | / enum NonEmptyEnum5 {