This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +19
-12
lines changed
rustc_error_messages/locales/en-US
tests/ui/pattern/usefulness/integer-ranges Expand file tree Collapse file tree 4 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -323,8 +323,6 @@ mir_build_overlapping_range_endpoints = multiple patterns overlap on their endpo
323323 .range = ... with this range
324324 .note = you likely meant to write mutually exclusive ranges
325325
326- mir_build_overlapping_range = this range overlaps on `{ $range } `...
327-
328326mir_build_non_exhaustive_omitted_pattern = some variants are not matched explicitly
329327 .help = ensure that all variants are matched explicitly by adding the suggested match arms
330328 .note = the matched value is of type `{ $scrut_ty } ` and the `non_exhaustive_omitted_patterns` attribute was found
Original file line number Diff line number Diff line change @@ -677,17 +677,28 @@ pub struct OverlappingRangeEndpoints<'tcx> {
677677 #[ label( range) ]
678678 pub range : Span ,
679679 #[ subdiagnostic]
680- pub overlap : Overlap < ' tcx > ,
680+ pub overlap : Vec < Overlap < ' tcx > > ,
681681}
682682
683- #[ derive( Subdiagnostic ) ]
684- #[ label( mir_build_overlapping_range) ]
685683pub struct Overlap < ' tcx > {
686- #[ primary_span]
687684 pub span : Span ,
688685 pub range : Pat < ' tcx > ,
689686}
690687
688+ impl < ' tcx > AddToDiagnostic for Overlap < ' tcx > {
689+ fn add_to_diagnostic_with < F > ( self , diag : & mut Diagnostic , _: F )
690+ where
691+ F : Fn ( & mut Diagnostic , SubdiagnosticMessage ) -> SubdiagnosticMessage ,
692+ {
693+ let Overlap { span, range } = self ;
694+
695+ // FIXME(mejrs) unfortunately `#[derive(LintDiagnostic)]`
696+ // does not support `#[subdiagnostic(eager)]`...
697+ let message = format ! ( "this range overlaps on `{range}`..." ) ;
698+ diag. span_label ( span, message) ;
699+ }
700+ }
701+
691702#[ derive( LintDiagnostic ) ]
692703#[ diag( mir_build_non_exhaustive_omitted_pattern) ]
693704#[ help]
Original file line number Diff line number Diff line change @@ -285,19 +285,16 @@ impl IntRange {
285285 return ;
286286 }
287287
288- // Get the first overlap. We get only the first rather than all of them
289- // because displaying multiple overlaps requires a way to eagerly translate
290- // lintdiagnostics, but that doesn't exist.
291- let overlap = pats
288+ let overlap: Vec < _ > = pats
292289 . filter_map ( |pat| Some ( ( pat. ctor ( ) . as_int_range ( ) ?, pat. span ( ) ) ) )
293290 . filter ( |( range, _) | self . suspicious_intersection ( range) )
294291 . map ( |( range, span) | Overlap {
295292 range : self . intersection ( & range) . unwrap ( ) . to_pat ( pcx. cx . tcx , pcx. ty ) ,
296293 span,
297294 } )
298- . next ( ) ;
295+ . collect ( ) ;
299296
300- if let Some ( overlap) = overlap {
297+ if ! overlap. is_empty ( ) {
301298 pcx. cx . tcx . emit_spanned_lint (
302299 lint:: builtin:: OVERLAPPING_RANGE_ENDPOINTS ,
303300 hir_id,
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ error: multiple patterns overlap on their endpoints
5959LL | 0..=10 => {}
6060 | ------ this range overlaps on `10_u8`...
6161LL | 20..=30 => {}
62+ | ------- this range overlaps on `20_u8`...
6263LL | 10..=20 => {}
6364 | ^^^^^^^ ... with this range
6465 |
You can’t perform that action at this time.
0 commit comments