diff options
| author | bors <bors@rust-lang.org> | 2024-03-10 05:19:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-10 05:19:18 +0000 |
| commit | 16316a960530bc966d48857dfb6a481c908b4665 (patch) | |
| tree | 700deae5c55afdbf41567b674b6e642c5b9c78e0 /compiler/rustc_pattern_analysis/src/errors.rs | |
| parent | ac968d4804a1990df1db99a865889e5e814dc2f6 (diff) | |
| parent | 2ecfbaef0a68fe6fb3aa7758d9a1bad531490365 (diff) | |
| download | rust-16316a960530bc966d48857dfb6a481c908b4665.tar.gz rust-16316a960530bc966d48857dfb6a481c908b4665.zip | |
Auto merge of #3371 - rust-lang:rustup-2024-03-10, r=saethlin
Automatic Rustup
Diffstat (limited to 'compiler/rustc_pattern_analysis/src/errors.rs')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/errors.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/compiler/rustc_pattern_analysis/src/errors.rs b/compiler/rustc_pattern_analysis/src/errors.rs index d0f56f0268d..e471b8abd73 100644 --- a/compiler/rustc_pattern_analysis/src/errors.rs +++ b/compiler/rustc_pattern_analysis/src/errors.rs @@ -77,6 +77,57 @@ impl<'tcx> AddToDiagnostic for Overlap<'tcx> { } #[derive(LintDiagnostic)] +#[diag(pattern_analysis_excluside_range_missing_max)] +pub struct ExclusiveRangeMissingMax<'tcx> { + #[label] + #[suggestion(code = "{suggestion}", applicability = "maybe-incorrect")] + /// This is an exclusive range that looks like `lo..max` (i.e. doesn't match `max`). + pub first_range: Span, + /// Suggest `lo..=max` instead. + pub suggestion: String, + pub max: Pat<'tcx>, +} + +#[derive(LintDiagnostic)] +#[diag(pattern_analysis_excluside_range_missing_gap)] +pub struct ExclusiveRangeMissingGap<'tcx> { + #[label] + #[suggestion(code = "{suggestion}", applicability = "maybe-incorrect")] + /// This is an exclusive range that looks like `lo..gap` (i.e. doesn't match `gap`). + pub first_range: Span, + pub gap: Pat<'tcx>, + /// Suggest `lo..=gap` instead. + pub suggestion: String, + #[subdiagnostic] + /// All these ranges skipped over `gap` which we think is probably a mistake. + pub gap_with: Vec<GappedRange<'tcx>>, +} + +pub struct GappedRange<'tcx> { + pub span: Span, + pub gap: Pat<'tcx>, + pub first_range: Pat<'tcx>, +} + +impl<'tcx> AddToDiagnostic for GappedRange<'tcx> { + fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( + self, + diag: &mut Diag<'_, G>, + _: F, + ) { + let GappedRange { span, gap, first_range } = self; + + // FIXME(mejrs) unfortunately `#[derive(LintDiagnostic)]` + // does not support `#[subdiagnostic(eager)]`... + 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(LintDiagnostic)] #[diag(pattern_analysis_non_exhaustive_omitted_pattern)] #[help] #[note] |
