Skip to content

Commit 1953130

Browse files
committed
Migrate unreachable pattern diagnostic
1 parent 6adcc31 commit 1953130

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

compiler/rustc_error_messages/locales/en-US/mir_build.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,7 @@ mir_build_assoc_const_in_pattern = associated consts cannot be referenced in pat
191191
mir_build_const_param_in_pattern = const parameters cannot be referenced in patterns
192192
193193
mir_build_non_const_path = runtime values cannot be referenced in patterns
194+
195+
mir_build_unreachable_pattern = unreachable pattern
196+
.label = unreachable pattern
197+
.catchall_label = matches any value

compiler/rustc_mir_build/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,12 @@ pub struct NonConstPath {
457457
#[primary_span]
458458
pub span: Span,
459459
}
460+
461+
#[derive(LintDiagnostic)]
462+
#[diag(mir_build::unreachable_pattern)]
463+
pub struct UnreachablePattern {
464+
#[label]
465+
pub span: Option<Span>,
466+
#[label(mir_build::catchall_label)]
467+
pub catchall: Option<Span>,
468+
}

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,12 @@ fn pat_is_catchall(pat: &DeconstructedPat<'_, '_>) -> bool {
592592
}
593593

594594
fn unreachable_pattern(tcx: TyCtxt<'_>, span: Span, id: HirId, catchall: Option<Span>) {
595-
tcx.struct_span_lint_hir(UNREACHABLE_PATTERNS, id, span, |lint| {
596-
let mut err = lint.build("unreachable pattern");
597-
if let Some(catchall) = catchall {
598-
// We had a catchall pattern, hint at that.
599-
err.span_label(span, "unreachable pattern");
600-
err.span_label(catchall, "matches any value");
601-
}
602-
err.emit();
603-
});
595+
tcx.emit_spanned_lint(
596+
UNREACHABLE_PATTERNS,
597+
id,
598+
span,
599+
UnreachablePattern { span: if catchall.is_some() { Some(span) } else { None }, catchall },
600+
);
604601
}
605602

606603
fn irrefutable_let_pattern(tcx: TyCtxt<'_>, id: HirId, span: Span) {

0 commit comments

Comments
 (0)