Migrate rustc_pattern_analysis lint to Diagnostic

This commit is contained in:
Guillaume Gomez
2026-03-04 11:32:19 +01:00
parent d933cf483e
commit ee855c02af
2 changed files with 7 additions and 9 deletions
@@ -1,5 +1,5 @@
use rustc_errors::{Diag, EmissionGuarantee, Subdiagnostic};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_middle::ty::Ty;
use rustc_span::Span;
@@ -131,10 +131,12 @@ pub(crate) struct NonExhaustiveOmittedPattern<'tcx> {
pub uncovered: Uncovered,
}
#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("the lint level must be set on the whole match")]
#[help("it no longer has any effect to set the lint level on an individual match arm")]
pub(crate) struct NonExhaustiveOmittedPatternLintOnArm {
#[primary_span]
pub span: Span,
#[label("remove this attribute")]
pub lint_span: Span,
#[suggestion(
+3 -7
View File
@@ -92,17 +92,13 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'p, 'tcx>(
let LevelAndSource { level, src, .. } =
rcx.tcx.lint_level_at_node(NON_EXHAUSTIVE_OMITTED_PATTERNS, arm.arm_data);
if !matches!(level, rustc_session::lint::Level::Allow) {
let decorator = NonExhaustiveOmittedPatternLintOnArm {
rcx.tcx.dcx().emit_warn(NonExhaustiveOmittedPatternLintOnArm {
span: arm.pat.data().span,
lint_span: src.span(),
suggest_lint_on_match: rcx.whole_match_span.map(|span| span.shrink_to_lo()),
lint_level: level.as_str(),
lint_name: "non_exhaustive_omitted_patterns",
};
use rustc_errors::LintDiagnostic;
let mut err = rcx.tcx.dcx().struct_span_warn(arm.pat.data().span, "");
decorator.decorate_lint(&mut err);
err.emit();
});
}
}
}