Translate Overlap
eagerly
This commit is contained in:
parent
3d260fa63c
commit
372ac9c1a2
4 changed files with 19 additions and 12 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue