mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Translate Overlap
eagerly
This commit is contained in:
parent
3d260fa63c
commit
372ac9c1a2
@ -323,8 +323,6 @@ mir_build_overlapping_range_endpoints = multiple patterns overlap on their endpo
|
||||
.range = ... with this range
|
||||
.note = you likely meant to write mutually exclusive ranges
|
||||
|
||||
mir_build_overlapping_range = this range overlaps on `{$range}`...
|
||||
|
||||
mir_build_non_exhaustive_omitted_pattern = some variants are not matched explicitly
|
||||
.help = ensure that all variants are matched explicitly by adding the suggested match arms
|
||||
.note = the matched value is of type `{$scrut_ty}` and the `non_exhaustive_omitted_patterns` attribute was found
|
||||
|
@ -677,17 +677,28 @@ pub struct OverlappingRangeEndpoints<'tcx> {
|
||||
#[label(range)]
|
||||
pub range: Span,
|
||||
#[subdiagnostic]
|
||||
pub overlap: Overlap<'tcx>,
|
||||
pub overlap: Vec<Overlap<'tcx>>,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[label(mir_build_overlapping_range)]
|
||||
pub struct Overlap<'tcx> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub range: Pat<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> AddToDiagnostic for Overlap<'tcx> {
|
||||
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
|
||||
where
|
||||
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
||||
{
|
||||
let Overlap { span, range } = self;
|
||||
|
||||
// FIXME(mejrs) unfortunately `#[derive(LintDiagnostic)]`
|
||||
// does not support `#[subdiagnostic(eager)]`...
|
||||
let message = format!("this range overlaps on `{range}`...");
|
||||
diag.span_label(span, message);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(mir_build_non_exhaustive_omitted_pattern)]
|
||||
#[help]
|
||||
|
@ -285,19 +285,16 @@ impl IntRange {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the first overlap. We get only the first rather than all of them
|
||||
// because displaying multiple overlaps requires a way to eagerly translate
|
||||
// lintdiagnostics, but that doesn't exist.
|
||||
let overlap = pats
|
||||
let overlap: Vec<_> = pats
|
||||
.filter_map(|pat| Some((pat.ctor().as_int_range()?, pat.span())))
|
||||
.filter(|(range, _)| self.suspicious_intersection(range))
|
||||
.map(|(range, span)| Overlap {
|
||||
range: self.intersection(&range).unwrap().to_pat(pcx.cx.tcx, pcx.ty),
|
||||
span,
|
||||
})
|
||||
.next();
|
||||
.collect();
|
||||
|
||||
if let Some(overlap) = overlap {
|
||||
if !overlap.is_empty() {
|
||||
pcx.cx.tcx.emit_spanned_lint(
|
||||
lint::builtin::OVERLAPPING_RANGE_ENDPOINTS,
|
||||
hir_id,
|
||||
|
@ -59,6 +59,7 @@ error: multiple patterns overlap on their endpoints
|
||||
LL | 0..=10 => {}
|
||||
| ------ this range overlaps on `10_u8`...
|
||||
LL | 20..=30 => {}
|
||||
| ------- this range overlaps on `20_u8`...
|
||||
LL | 10..=20 => {}
|
||||
| ^^^^^^^ ... with this range
|
||||
|
|
||||
|
Loading…
Reference in New Issue
Block a user