@@ -217,7 +217,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
217217 if def. variants . len ( ) < 4 && !def. variants . is_empty ( ) {
218218 // keep around to point at the definition of non-covered variants
219219 missing_variants = def. variants . iter ( )
220- . map ( |variant| variant. ident . span )
220+ . map ( |variant| variant. ident )
221221 . collect ( ) ;
222222 }
223223 def. variants . is_empty ( )
@@ -227,18 +227,27 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
227227 } ;
228228 if !scrutinee_is_uninhabited {
229229 // 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+ ) ;
234243 err. help ( "ensure that all possible cases are being handled, \
235244 possibly by adding wildcards or more match arms") ;
236245 if let Some ( sp) = def_span {
237246 err. span_label ( sp, format ! ( "`{}` defined here" , pat_ty) ) ;
238247 }
239248 // point at the definition of non-covered enum variants
240249 for variant in & missing_variants {
241- err. span_label ( * variant, "variant not covered" ) ;
250+ err. span_label ( variant. span , "variant not covered" ) ;
242251 }
243252 err. emit ( ) ;
244253 }
@@ -508,7 +517,8 @@ fn maybe_point_at_variant(
508517) -> Vec < Span > {
509518 let mut covered = vec ! [ ] ;
510519 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
512522 for pattern in patterns {
513523 let pk: & PatternKind < ' _ > = & pattern. kind ;
514524 if let PatternKind :: Variant { adt_def, variant_index, subpatterns, .. } = pk {
@@ -526,7 +536,7 @@ fn maybe_point_at_variant(
526536 ) ;
527537 }
528538 }
529- if let PatternKind :: Leaf { subpatterns } = pk {
539+ if let PatternKind :: Leaf { subpatterns } = pk {
530540 let subpatterns = subpatterns. iter ( )
531541 . map ( |field_pattern| field_pattern. pattern . clone ( ) )
532542 . collect :: < Vec < _ > > ( ) ;
0 commit comments