From b9c0467e0c87c38009087eea65a79994d6bf1f26 Mon Sep 17 00:00:00 2001 From: pierwill Date: Sun, 2 Oct 2022 16:02:57 -0500 Subject: [PATCH] Add diagnostic struct for const eval error in `rustc_middle` Co-authored-by: Michael Goulet --- compiler/rustc_error_messages/locales/en-US/middle.ftl | 3 +++ compiler/rustc_middle/src/error.rs | 7 +++++++ compiler/rustc_middle/src/ty/adt.rs | 8 +++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_error_messages/locales/en-US/middle.ftl b/compiler/rustc_error_messages/locales/en-US/middle.ftl index ed834886453..ca3c91ce24a 100644 --- a/compiler/rustc_error_messages/locales/en-US/middle.ftl +++ b/compiler/rustc_error_messages/locales/en-US/middle.ftl @@ -15,3 +15,6 @@ middle_previous_use_here = middle_limit_invalid = `limit` must be a non-negative integer .label = {$error_str} + +middle_const_eval_non_int = + constant evaluation of enum discriminant resulted in non-integer diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs index a4ceb494569..e69cb546d15 100644 --- a/compiler/rustc_middle/src/error.rs +++ b/compiler/rustc_middle/src/error.rs @@ -48,3 +48,10 @@ pub struct LimitInvalid<'a> { pub value_span: Span, pub error_str: &'a str, } + +#[derive(Diagnostic)] +#[diag(middle::const_eval_non_int)] +pub struct ConstEvalNonIntError { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index 74ce0b38ed2..3c485e26409 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -458,11 +458,9 @@ pub fn eval_explicit_discr(self, tcx: TyCtxt<'tcx>, expr_did: DefId) -> Option