Skip to content

Commit 65c736e

Browse files
committed
Migrate "constant pattern depends on generic parameter" diagnostic
1 parent 1953130 commit 65c736e

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,6 @@ mir_build_non_const_path = runtime values cannot be referenced in patterns
195195
mir_build_unreachable_pattern = unreachable pattern
196196
.label = unreachable pattern
197197
.catchall_label = matches any value
198+
199+
mir_build_const_pattern_depends_on_generic_parameter =
200+
constant pattern depends on a generic parameter

compiler/rustc_mir_build/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,10 @@ pub struct UnreachablePattern {
466466
#[label(mir_build::catchall_label)]
467467
pub catchall: Option<Span>,
468468
}
469+
470+
#[derive(SessionDiagnostic)]
471+
#[diag(mir_build::const_pattern_depends_on_generic_parameter)]
472+
pub struct ConstPatternDependsOnGenericParameter {
473+
#[primary_span]
474+
pub span: Span,
475+
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod usefulness;
88
pub(crate) use self::check_match::check_match;
99
pub(crate) use self::usefulness::MatchCheckCtxt;
1010

11+
use crate::errors::ConstPatternDependsOnGenericParameter;
1112
use crate::thir::util::UserAnnotatedTyHelpers;
1213

1314
use rustc_errors::struct_span_err;
@@ -530,7 +531,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
530531
Err(ErrorHandled::TooGeneric) => {
531532
// While `Reported | Linted` cases will have diagnostics emitted already
532533
// it is not true for TooGeneric case, so we need to give user more information.
533-
self.tcx.sess.span_err(span, "constant pattern depends on a generic parameter");
534+
self.tcx.sess.emit_err(ConstPatternDependsOnGenericParameter { span });
534535
pat_from_kind(PatKind::Wild)
535536
}
536537
Err(_) => {
@@ -562,9 +563,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
562563
}
563564
ConstKind::Unevaluated(_) => {
564565
// If we land here it means the const can't be evaluated because it's `TooGeneric`.
565-
self.tcx
566-
.sess
567-
.span_err(span, "constant pattern depends on a generic parameter");
566+
self.tcx.sess.emit_err(ConstPatternDependsOnGenericParameter { span });
568567
return PatKind::Wild;
569568
}
570569
_ => bug!("Expected either ConstKind::Param or ConstKind::Unevaluated"),

0 commit comments

Comments
 (0)