Navigation Menu

Skip to content

Commit

Permalink
Tweak error on empty match
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Dec 4, 2019
1 parent b26aa0b commit 1bd97ae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/librustc_mir/hair/pattern/check_match.rs
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/pattern/usefulness/match-empty.rs
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/test/ui/pattern/usefulness/match-empty.stderr
Expand Up @@ -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 {
Expand Down

0 comments on commit 1bd97ae

Please sign in to comment.