Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate rustc_mir_build diagnostics #104417

Merged
merged 18 commits into from
Dec 18, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate unreachable pattern diagnostic
  • Loading branch information
lzcunt authored and mejrs committed Dec 17, 2022
commit b694e6649ef5883e36c1bbac0c9890db5dd96792
4 changes: 4 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/mir_build.ftl
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions compiler/rustc_mir_build/src/errors.rs
Original file line number Diff line number Diff line change
@@ -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>,
}
14 changes: 6 additions & 8 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
@@ -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) {