Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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) {
Expand Down