Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 60b12fd

Browse files
committedJan 5, 2024
unstably allow constants to refer to statics and read from immutable statics
1 parent 42c4e69 commit 60b12fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+541
-521
lines changed
 

‎compiler/rustc_const_eval/messages.ftl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ const_eval_closure_non_const =
3030
cannot call non-const closure in {const_eval_const_context}s
3131
const_eval_consider_dereferencing =
3232
consider dereferencing here
33-
const_eval_const_accesses_static = constant accesses static
33+
34+
const_eval_const_accesses_mut_global =
35+
constant accesses mutable global memory
3436
3537
const_eval_const_context = {$kind ->
3638
[const] constant
@@ -213,6 +215,9 @@ const_eval_modified_global =
213215
const_eval_mut_deref =
214216
mutation through a reference is not allowed in {const_eval_const_context}s
215217
218+
const_eval_mutable_data_in_const =
219+
constant refers to mutable data
220+
216221
const_eval_mutable_ptr_in_final = encountered mutable pointer in final value of {const_eval_intern_kind}
217222
218223
const_eval_non_const_fmt_macro_call =
@@ -319,12 +324,6 @@ const_eval_size_overflow =
319324
const_eval_stack_frame_limit_reached =
320325
reached the configured maximum number of stack frames
321326
322-
const_eval_static_access =
323-
{const_eval_const_context}s cannot refer to statics
324-
.help = consider extracting the value of the `static` to a `const`, and referring to that
325-
.teach_note = `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable.
326-
.teach_help = To fix this, the value can be extracted to a `const` and then used.
327-
328327
const_eval_thread_local_access =
329328
thread-local statics cannot be accessed at compile-time
330329

‎compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::interpret::{ErrorHandled, InterpError, InterpErrorInfo, MachineStopTy
1515
/// The CTFE machine has some custom error kinds.
1616
#[derive(Clone, Debug)]
1717
pub enum ConstEvalErrKind {
18-
ConstAccessesStatic,
18+
ConstAccessesMutGlobal,
1919
ModifiedGlobal,
2020
AssertFailure(AssertKind<ConstInt>),
2121
Panic { msg: Symbol, line: u32, col: u32, file: Symbol },
@@ -26,7 +26,7 @@ impl MachineStopType for ConstEvalErrKind {
2626
use crate::fluent_generated::*;
2727
use ConstEvalErrKind::*;
2828
match self {
29-
ConstAccessesStatic => const_eval_const_accesses_static,
29+
ConstAccessesMutGlobal => const_eval_const_accesses_mut_global,
3030
ModifiedGlobal => const_eval_modified_global,
3131
Panic { .. } => const_eval_panic,
3232
AssertFailure(x) => x.diagnostic_message(),
@@ -38,7 +38,7 @@ impl MachineStopType for ConstEvalErrKind {
3838
) {
3939
use ConstEvalErrKind::*;
4040
match *self {
41-
ConstAccessesStatic | ModifiedGlobal => {}
41+
ConstAccessesMutGlobal | ModifiedGlobal => {}
4242
AssertFailure(kind) => kind.add_args(adder),
4343
Panic { msg, line, col, file } => {
4444
adder("msg".into(), msg.into_diagnostic_arg());

0 commit comments

Comments
 (0)
Please sign in to comment.