From 1c4afbd1de7a0aa548a4b8f184aede5c5954e63a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 28 Jun 2022 21:46:01 -0700 Subject: [PATCH] Migrate NonConstOp diagnostic --- compiler/rustc_const_eval/src/errors.rs | 7 +++++++ .../rustc_const_eval/src/transform/check_consts/ops.rs | 9 ++------- .../rustc_error_messages/locales/en-US/const_eval.ftl | 3 +++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index f19e8046d42..40398011f1f 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -19,3 +19,10 @@ pub(crate) struct UnstableInStable { )] pub attr_span: Span, } + +#[derive(SessionDiagnostic)] +#[error(const_eval::thread_local_access, code = "E0625")] +pub(crate) struct NonConstOpErr { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index 9574661282b..01080560021 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -20,6 +20,7 @@ use rustc_span::{BytePos, Pos, Span, Symbol}; use rustc_trait_selection::traits::SelectionContext; use super::ConstCx; +use crate::errors::NonConstOpErr; use crate::util::{call_kind, CallDesugaringKind, CallKind}; #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -760,13 +761,7 @@ impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess { ccx: &ConstCx<'_, 'tcx>, span: Span, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { - struct_span_err!( - ccx.tcx.sess, - span, - E0625, - "thread-local statics cannot be \ - accessed at compile-time" - ) + ccx.tcx.sess.create_err(NonConstOpErr { span }) } } diff --git a/compiler/rustc_error_messages/locales/en-US/const_eval.ftl b/compiler/rustc_error_messages/locales/en-US/const_eval.ftl index a022e596efb..897ddce7e99 100644 --- a/compiler/rustc_error_messages/locales/en-US/const_eval.ftl +++ b/compiler/rustc_error_messages/locales/en-US/const_eval.ftl @@ -2,3 +2,6 @@ const-eval-unstable-in-stable = const-stable function cannot use `#[feature({$gate})]` .unstable-sugg = if it is not part of the public API, make this function unstably const .bypass-sugg = otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks + +const-eval-thread-local-access = + thread-local statics cannot be accessed at compile-time \ No newline at end of file