Skip to content

Commit 1c4afbd

Browse files
Migrate NonConstOp diagnostic
1 parent 934079f commit 1c4afbd

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

compiler/rustc_const_eval/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ pub(crate) struct UnstableInStable {
1919
)]
2020
pub attr_span: Span,
2121
}
22+
23+
#[derive(SessionDiagnostic)]
24+
#[error(const_eval::thread_local_access, code = "E0625")]
25+
pub(crate) struct NonConstOpErr {
26+
#[primary_span]
27+
pub span: Span,
28+
}

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_span::{BytePos, Pos, Span, Symbol};
2020
use rustc_trait_selection::traits::SelectionContext;
2121

2222
use super::ConstCx;
23+
use crate::errors::NonConstOpErr;
2324
use crate::util::{call_kind, CallDesugaringKind, CallKind};
2425

2526
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -760,13 +761,7 @@ impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess {
760761
ccx: &ConstCx<'_, 'tcx>,
761762
span: Span,
762763
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
763-
struct_span_err!(
764-
ccx.tcx.sess,
765-
span,
766-
E0625,
767-
"thread-local statics cannot be \
768-
accessed at compile-time"
769-
)
764+
ccx.tcx.sess.create_err(NonConstOpErr { span })
770765
}
771766
}
772767

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

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ const-eval-unstable-in-stable =
22
const-stable function cannot use `#[feature({$gate})]`
33
.unstable-sugg = if it is not part of the public API, make this function unstably const
44
.bypass-sugg = otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
5+
6+
const-eval-thread-local-access =
7+
thread-local statics cannot be accessed at compile-time

0 commit comments

Comments
 (0)