@@ -217,7 +217,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
217
217
if def. variants . len ( ) < 4 && !def. variants . is_empty ( ) {
218
218
// keep around to point at the definition of non-covered variants
219
219
missing_variants = def. variants . iter ( )
220
- . map ( |variant| variant. ident . span )
220
+ . map ( |variant| variant. ident )
221
221
. collect ( ) ;
222
222
}
223
223
def. variants . is_empty ( )
@@ -227,18 +227,27 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
227
227
} ;
228
228
if !scrutinee_is_uninhabited {
229
229
// We know the type is inhabited, so this must be wrong
230
- let mut err = create_e0004 ( self . tcx . sess , scrut. span , format ! (
231
- "non-exhaustive patterns: type `{}` is non-empty" ,
232
- pat_ty,
233
- ) ) ;
230
+ let mut err = create_e0004 (
231
+ self . tcx . sess ,
232
+ scrut. span ,
233
+ format ! ( "non-exhaustive patterns: {}" , match missing_variants. len( ) {
234
+ 0 => format!( "type `{}` is non-empty" , pat_ty) ,
235
+ 1 => format!(
236
+ "pattern `{}` of type `{}` is not handled" ,
237
+ missing_variants[ 0 ] . name,
238
+ pat_ty,
239
+ ) ,
240
+ _ => format!( "multiple patterns of type `{}` are not handled" , pat_ty) ,
241
+ } ) ,
242
+ ) ;
234
243
err. help ( "ensure that all possible cases are being handled, \
235
244
possibly by adding wildcards or more match arms") ;
236
245
if let Some ( sp) = def_span {
237
246
err. span_label ( sp, format ! ( "`{}` defined here" , pat_ty) ) ;
238
247
}
239
248
// point at the definition of non-covered enum variants
240
249
for variant in & missing_variants {
241
- err. span_label ( * variant, "variant not covered" ) ;
250
+ err. span_label ( variant. span , "variant not covered" ) ;
242
251
}
243
252
err. emit ( ) ;
244
253
}
@@ -508,7 +517,8 @@ fn maybe_point_at_variant(
508
517
) -> Vec < Span > {
509
518
let mut covered = vec ! [ ] ;
510
519
if let ty:: Adt ( def, _) = sty {
511
- // Don't point at the variants if they are too many to avoid visual clutter
520
+ // Don't point at variants that have already been covered due to other patterns to avoid
521
+ // visual clutter
512
522
for pattern in patterns {
513
523
let pk: & PatternKind < ' _ > = & pattern. kind ;
514
524
if let PatternKind :: Variant { adt_def, variant_index, subpatterns, .. } = pk {
@@ -526,7 +536,7 @@ fn maybe_point_at_variant(
526
536
) ;
527
537
}
528
538
}
529
- if let PatternKind :: Leaf { subpatterns } = pk {
539
+ if let PatternKind :: Leaf { subpatterns } = pk {
530
540
let subpatterns = subpatterns. iter ( )
531
541
. map ( |field_pattern| field_pattern. pattern . clone ( ) )
532
542
. collect :: < Vec < _ > > ( ) ;
0 commit comments