@@ -917,22 +917,28 @@ fn report_unreachable_pattern<'p, 'tcx>(
917917 pat : & DeconstructedPat < ' p , ' tcx > ,
918918 explanation : & RedundancyExplanation < ' p , ' tcx > ,
919919) {
920+ static CAP_COVERED_BY_MANY : usize = 4 ;
920921 let pat_span = pat. data ( ) . span ;
921922 let mut lint = UnreachablePattern {
922923 span : Some ( pat_span) ,
923924 matches_no_values : None ,
925+ matches_no_values_ty : * * pat. ty ( ) ,
926+ uninhabited_note : None ,
924927 covered_by_catchall : None ,
925928 covered_by_one : None ,
926929 covered_by_many : None ,
930+ covered_by_many_n_more_count : 0 ,
927931 } ;
928932 match explanation. covered_by . as_slice ( ) {
929933 [ ] => {
930934 // Empty pattern; we report the uninhabited type that caused the emptiness.
931935 lint. span = None ; // Don't label the pattern itself
936+ lint. uninhabited_note = Some ( ( ) ) ; // Give a link about empty types
937+ lint. matches_no_values = Some ( pat_span) ;
932938 pat. walk ( & mut |subpat| {
933939 let ty = * * subpat. ty ( ) ;
934940 if cx. is_uninhabited ( ty) {
935- lint. matches_no_values = Some ( UnreachableMatchesNoValues { ty } ) ;
941+ lint. matches_no_values_ty = ty ;
936942 false // No need to dig further.
937943 } else if matches ! ( subpat. ctor( ) , Constructor :: Ref | Constructor :: UnionField ) {
938944 false // Don't explore further since they are not by-value.
@@ -948,15 +954,27 @@ fn report_unreachable_pattern<'p, 'tcx>(
948954 lint. covered_by_one = Some ( covering_pat. data ( ) . span ) ;
949955 }
950956 covering_pats => {
957+ let mut iter = covering_pats. iter ( ) ;
951958 let mut multispan = MultiSpan :: from_span ( pat_span) ;
952- for p in covering_pats {
959+ for p in iter . by_ref ( ) . take ( CAP_COVERED_BY_MANY ) {
953960 multispan. push_span_label (
954961 p. data ( ) . span ,
955962 fluent:: mir_build_unreachable_matches_same_values,
956963 ) ;
957964 }
958- multispan
959- . push_span_label ( pat_span, fluent:: mir_build_unreachable_making_this_unreachable) ;
965+ let remain = iter. count ( ) ;
966+ if remain == 0 {
967+ multispan. push_span_label (
968+ pat_span,
969+ fluent:: mir_build_unreachable_making_this_unreachable,
970+ ) ;
971+ } else {
972+ lint. covered_by_many_n_more_count = remain;
973+ multispan. push_span_label (
974+ pat_span,
975+ fluent:: mir_build_unreachable_making_this_unreachable_n_more,
976+ ) ;
977+ }
960978 lint. covered_by_many = Some ( multispan) ;
961979 }
962980 }
0 commit comments