@@ -917,22 +917,28 @@ fn report_unreachable_pattern<'p, 'tcx>(
917
917
pat : & DeconstructedPat < ' p , ' tcx > ,
918
918
explanation : & RedundancyExplanation < ' p , ' tcx > ,
919
919
) {
920
+ static CAP_COVERED_BY_MANY : usize = 4 ;
920
921
let pat_span = pat. data ( ) . span ;
921
922
let mut lint = UnreachablePattern {
922
923
span : Some ( pat_span) ,
923
924
matches_no_values : None ,
925
+ matches_no_values_ty : * * pat. ty ( ) ,
926
+ uninhabited_note : None ,
924
927
covered_by_catchall : None ,
925
928
covered_by_one : None ,
926
929
covered_by_many : None ,
930
+ covered_by_many_n_more_count : 0 ,
927
931
} ;
928
932
match explanation. covered_by . as_slice ( ) {
929
933
[ ] => {
930
934
// Empty pattern; we report the uninhabited type that caused the emptiness.
931
935
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) ;
932
938
pat. walk ( & mut |subpat| {
933
939
let ty = * * subpat. ty ( ) ;
934
940
if cx. is_uninhabited ( ty) {
935
- lint. matches_no_values = Some ( UnreachableMatchesNoValues { ty } ) ;
941
+ lint. matches_no_values_ty = ty ;
936
942
false // No need to dig further.
937
943
} else if matches ! ( subpat. ctor( ) , Constructor :: Ref | Constructor :: UnionField ) {
938
944
false // Don't explore further since they are not by-value.
@@ -948,15 +954,27 @@ fn report_unreachable_pattern<'p, 'tcx>(
948
954
lint. covered_by_one = Some ( covering_pat. data ( ) . span ) ;
949
955
}
950
956
covering_pats => {
957
+ let mut iter = covering_pats. iter ( ) ;
951
958
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 ) {
953
960
multispan. push_span_label (
954
961
p. data ( ) . span ,
955
962
fluent:: mir_build_unreachable_matches_same_values,
956
963
) ;
957
964
}
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
+ }
960
978
lint. covered_by_many = Some ( multispan) ;
961
979
}
962
980
}
0 commit comments