Skip to content

Commit 1bd97ae

Browse files
committed
Tweak error on empty match
1 parent b26aa0b commit 1bd97ae

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/librustc_mir/hair/pattern/check_match.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,8 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
180180
ty::Never => true,
181181
ty::Adt(def, _) => {
182182
def_span = self.tcx.hir().span_if_local(def.did);
183-
if def.variants.len() < 4 && !def.variants.is_empty() {
184-
// keep around to point at the definition of non-covered variants
185-
missing_variants =
186-
def.variants.iter().map(|variant| variant.ident).collect();
187-
}
183+
missing_variants =
184+
def.variants.iter().map(|variant| variant.ident).collect();
188185

189186
def.variants.is_empty() && !cx.is_foreign_non_exhaustive_enum(pat_ty)
190187
}
@@ -219,8 +216,10 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
219216
err.span_label(sp, format!("`{}` defined here", pat_ty));
220217
}
221218
// point at the definition of non-covered enum variants
222-
for variant in &missing_variants {
223-
err.span_label(variant.span, "variant not covered");
219+
if missing_variants.len() < 4 {
220+
for variant in &missing_variants {
221+
err.span_label(variant.span, "variant not covered");
222+
}
224223
}
225224
err.emit();
226225
}

src/test/ui/pattern/usefulness/match-empty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ fn main() {
4444
match NonEmptyEnum2::Foo(true) {}
4545
//~^ ERROR multiple patterns of type `NonEmptyEnum2` are not handled
4646
match NonEmptyEnum5::V1 {}
47-
//~^ ERROR type `NonEmptyEnum5` is non-empty
47+
//~^ ERROR multiple patterns of type `NonEmptyEnum5` are not handled
4848
}

src/test/ui/pattern/usefulness/match-empty.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ LL | match NonEmptyEnum2::Foo(true) {}
5050
|
5151
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
5252

53-
error[E0004]: non-exhaustive patterns: type `NonEmptyEnum5` is non-empty
53+
error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum5` are not handled
5454
--> $DIR/match-empty.rs:46:11
5555
|
5656
LL | / enum NonEmptyEnum5 {

0 commit comments

Comments
 (0)