mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Migrate rustc_pattern_analysis lint to Diagnostic
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user