diff --git a/compiler/rustc_pattern_analysis/src/errors.rs b/compiler/rustc_pattern_analysis/src/errors.rs index 514d1e2a9729..109acf0ec410 100644 --- a/compiler/rustc_pattern_analysis/src/errors.rs +++ b/compiler/rustc_pattern_analysis/src/errors.rs @@ -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, } +#[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(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")]