1
Fork 0

Make LevelAndSource a struct

This commit is contained in:
Oli Scherer 2025-03-19 09:41:38 +00:00
parent f3eaf1624c
commit c51816ee59
23 changed files with 105 additions and 86 deletions

View file

@ -1,3 +1,4 @@
use rustc_middle::lint::LevelAndSource;
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
use rustc_span::ErrorGuaranteed;
use tracing::instrument;
@ -64,7 +65,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'p, 'tcx>(
scrut_ty: RevealedTy<'tcx>,
) -> Result<(), ErrorGuaranteed> {
if !matches!(
rcx.tcx.lint_level_at_node(NON_EXHAUSTIVE_OMITTED_PATTERNS, rcx.match_lint_level).0,
rcx.tcx.lint_level_at_node(NON_EXHAUSTIVE_OMITTED_PATTERNS, rcx.match_lint_level).level,
rustc_session::lint::Level::Allow
) {
let witnesses = collect_nonexhaustive_missing_variants(rcx, pat_column)?;
@ -88,13 +89,13 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'p, 'tcx>(
// arm. This no longer makes sense so we warn users, to avoid silently breaking their
// usage of the lint.
for arm in arms {
let (lint_level, lint_level_source) =
let LevelAndSource { level, src } =
rcx.tcx.lint_level_at_node(NON_EXHAUSTIVE_OMITTED_PATTERNS, arm.arm_data);
if !matches!(lint_level, rustc_session::lint::Level::Allow) {
if !matches!(level, rustc_session::lint::Level::Allow) {
let decorator = NonExhaustiveOmittedPatternLintOnArm {
lint_span: lint_level_source.span(),
lint_span: src.span(),
suggest_lint_on_match: rcx.whole_match_span.map(|span| span.shrink_to_lo()),
lint_level: lint_level.as_str(),
lint_level: level.as_str(),
lint_name: "non_exhaustive_omitted_patterns",
};