Skip to content

Commit baa6c15

Browse files
lzcuntmejrs
authored andcommitted
Migrate "could not evaluate const pattern" diagnostic
1 parent 75694d5 commit baa6c15

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,5 @@ mir_build_unreachable_pattern = unreachable pattern
198198
199199
mir_build_const_pattern_depends_on_generic_parameter =
200200
constant pattern depends on a generic parameter
201+
202+
mir_build_could_not_eval_const_pattern = could not evaluate constant pattern

compiler/rustc_mir_build/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,10 @@ pub struct ConstPatternDependsOnGenericParameter {
473473
#[primary_span]
474474
pub span: Span,
475475
}
476+
477+
#[derive(SessionDiagnostic)]
478+
#[diag(mir_build::could_not_eval_const_pattern)]
479+
pub struct CouldNotEvalConstPattern {
480+
#[primary_span]
481+
pub span: Span,
482+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +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;
11+
use crate::errors::*;
1212
use crate::thir::util::UserAnnotatedTyHelpers;
1313

1414
use rustc_errors::struct_span_err;
@@ -503,7 +503,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
503503
}
504504

505505
Err(_) => {
506-
self.tcx.sess.span_err(span, "could not evaluate constant pattern");
506+
self.tcx.sess.emit_err(CouldNotEvalConstPattern { span });
507507
return pat_from_kind(PatKind::Wild);
508508
}
509509
};
@@ -554,7 +554,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
554554
pat_from_kind(PatKind::Wild)
555555
}
556556
Err(_) => {
557-
self.tcx.sess.span_err(span, "could not evaluate constant pattern");
557+
self.tcx.sess.emit_err(CouldNotEvalConstPattern { span });
558558
pat_from_kind(PatKind::Wild)
559559
}
560560
}

0 commit comments

Comments
 (0)