Commit 372ac9c 1 parent 3d260fa commit 372ac9c Copy full SHA for 372ac9c
File tree 4 files changed +19
-12
lines changed
rustc_error_messages/locales/en-US
tests/ui/pattern/usefulness/integer-ranges
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
323
323
.range = ... with this range
324
324
.note = you likely meant to write mutually exclusive ranges
325
325
326
- mir_build_overlapping_range = this range overlaps on `{ $range } `...
327
-
328
326
mir_build_non_exhaustive_omitted_pattern = some variants are not matched explicitly
329
327
.help = ensure that all variants are matched explicitly by adding the suggested match arms
330
328
.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> {
677
677
#[ label( range) ]
678
678
pub range : Span ,
679
679
#[ subdiagnostic]
680
- pub overlap : Overlap < ' tcx > ,
680
+ pub overlap : Vec < Overlap < ' tcx > > ,
681
681
}
682
682
683
- #[ derive( Subdiagnostic ) ]
684
- #[ label( mir_build_overlapping_range) ]
685
683
pub struct Overlap < ' tcx > {
686
- #[ primary_span]
687
684
pub span : Span ,
688
685
pub range : Pat < ' tcx > ,
689
686
}
690
687
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
+
691
702
#[ derive( LintDiagnostic ) ]
692
703
#[ diag( mir_build_non_exhaustive_omitted_pattern) ]
693
704
#[ help]
Original file line number Diff line number Diff line change @@ -285,19 +285,16 @@ impl IntRange {
285
285
return ;
286
286
}
287
287
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
292
289
. filter_map ( |pat| Some ( ( pat. ctor ( ) . as_int_range ( ) ?, pat. span ( ) ) ) )
293
290
. filter ( |( range, _) | self . suspicious_intersection ( range) )
294
291
. map ( |( range, span) | Overlap {
295
292
range : self . intersection ( & range) . unwrap ( ) . to_pat ( pcx. cx . tcx , pcx. ty ) ,
296
293
span,
297
294
} )
298
- . next ( ) ;
295
+ . collect ( ) ;
299
296
300
- if let Some ( overlap) = overlap {
297
+ if ! overlap. is_empty ( ) {
301
298
pcx. cx . tcx . emit_spanned_lint (
302
299
lint:: builtin:: OVERLAPPING_RANGE_ENDPOINTS ,
303
300
hir_id,
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ error: multiple patterns overlap on their endpoints
59
59
LL | 0..=10 => {}
60
60
| ------ this range overlaps on `10_u8`...
61
61
LL | 20..=30 => {}
62
+ | ------- this range overlaps on `20_u8`...
62
63
LL | 10..=20 => {}
63
64
| ^^^^^^^ ... with this range
64
65
|
You can’t perform that action at this time.
0 commit comments