File tree Expand file tree Collapse file tree 3 files changed +8
-9
lines changed
librustc_mir/hair/pattern
test/ui/pattern/usefulness Expand file tree Collapse file tree 3 files changed +8
-9
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 |
5656LL | / enum NonEmptyEnum5 {
You can’t perform that action at this time.
0 commit comments