mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Use derived impl for GappedRange subdiagnostic
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use rustc_errors::{Diag, EmissionGuarantee, Subdiagnostic};
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_middle::ty::Ty;
|
||||
use rustc_span::Span;
|
||||
@@ -99,25 +98,17 @@ pub struct ExclusiveRangeMissingGap {
|
||||
pub gap_with: Vec<GappedRange>,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[label(
|
||||
"this could appear to continue range `{$first_range}`, but `{$gap}` isn't matched by either of them"
|
||||
)]
|
||||
pub struct GappedRange {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub gap: String, // a printed pattern
|
||||
pub first_range: String, // a printed pattern
|
||||
}
|
||||
|
||||
impl Subdiagnostic for GappedRange {
|
||||
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
let GappedRange { span, gap, first_range } = self;
|
||||
|
||||
// FIXME(mejrs) Use `#[subdiagnostic(eager)]` instead
|
||||
let message = format!(
|
||||
"this could appear to continue range `{first_range}`, but `{gap}` isn't matched by \
|
||||
either of them"
|
||||
);
|
||||
diag.span_label(span, message);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("some variants are not matched explicitly")]
|
||||
#[help("ensure that all variants are matched explicitly by adding the suggested match arms")]
|
||||
|
||||
Reference in New Issue
Block a user