Skip to content

Commit 7d0d2de

Browse files
lzcuntmejrs
authored andcommitted
Migrate unreachable pattern diagnostic
1 parent 85c6818 commit 7d0d2de

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -605,14 +605,12 @@ fn pat_is_catchall(pat: &DeconstructedPat<'_, '_>) -> bool {
605605
}
606606

607607
fn unreachable_pattern(tcx: TyCtxt<'_>, span: Span, id: HirId, catchall: Option<Span>) {
608-
tcx.struct_span_lint_hir(UNREACHABLE_PATTERNS, id, span, "unreachable pattern", |lint| {
609-
if let Some(catchall) = catchall {
610-
// We had a catchall pattern, hint at that.
611-
lint.span_label(span, "unreachable pattern");
612-
lint.span_label(catchall, "matches any value");
613-
}
614-
lint
615-
});
608+
tcx.emit_spanned_lint(
609+
UNREACHABLE_PATTERNS,
610+
id,
611+
span,
612+
UnreachablePattern { span: if catchall.is_some() { Some(span) } else { None }, catchall },
613+
);
616614
}
617615

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

0 commit comments

Comments
 (0)