Migrate unreachable pattern diagnostic

This commit is contained in:
TheOddGarlic 2022-08-27 22:06:06 +03:00 committed by mejrs
parent 98442b6905
commit b694e6649e
3 changed files with 19 additions and 8 deletions

View file

@ -191,3 +191,7 @@ mir_build_assoc_const_in_pattern = associated consts cannot be referenced in pat
mir_build_const_param_in_pattern = const parameters cannot be referenced in patterns
mir_build_non_const_path = runtime values cannot be referenced in patterns
mir_build_unreachable_pattern = unreachable pattern
.label = unreachable pattern
.catchall_label = matches any value

View file

@ -457,3 +457,12 @@ pub struct NonConstPath {
#[primary_span]
pub span: Span,
}
#[derive(LintDiagnostic)]
#[diag(mir_build::unreachable_pattern)]
pub struct UnreachablePattern {
#[label]
pub span: Option<Span>,
#[label(mir_build::catchall_label)]
pub catchall: Option<Span>,
}

View file

@ -605,14 +605,12 @@ fn pat_is_catchall(pat: &DeconstructedPat<'_, '_>) -> bool {
}
fn unreachable_pattern(tcx: TyCtxt<'_>, span: Span, id: HirId, catchall: Option<Span>) {
tcx.struct_span_lint_hir(UNREACHABLE_PATTERNS, id, span, "unreachable pattern", |lint| {
if let Some(catchall) = catchall {
// We had a catchall pattern, hint at that.
lint.span_label(span, "unreachable pattern");
lint.span_label(catchall, "matches any value");
}
lint
});
tcx.emit_spanned_lint(
UNREACHABLE_PATTERNS,
id,
span,
UnreachablePattern { span: if catchall.is_some() { Some(span) } else { None }, catchall },
);
}
fn irrefutable_let_pattern(tcx: TyCtxt<'_>, id: HirId, span: Span) {