Closed
Description
Code
#![feature(thread_local)]
#[thread_local]
static mut STATIC_VAR_2: [u32; 8] = [4; 8];
const fn g(x: &mut [u32; 8]) {
std::mem::swap(x, &mut STATIC_VAR_2)
}
Meta
rustc --version --verbose
:
rustc 1.54.0-nightly (9111b8ae9 2021-05-26)
binary: rustc
commit-hash: 9111b8ae9793f18179a1336417618fc07a9cac85
commit-date: 2021-05-26
host: x86_64-unknown-linux-gnu
release: 1.54.0-nightly
LLVM version: 12.0.1
Error output
error[E0658]: mutable references are not allowed in constant functions
--> mutant.rs:4:12
|
4 | const fn g(x: &mut [u32; 8]) {
| ^
|
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
error[E0625]: thread-local statics cannot be accessed at compile-time
--> mutant.rs:5:28
|
5 | std::mem::swap(x, &mut STATIC_VAR_2)
| ^^^^^^^^^^^^
thread 'rustc' panicked at 'tls access is checked in `Rvalue::ThreadLocalRef', compiler/rustc_mir/src/transform/check_consts/validation.rs:359:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.54.0-nightly (9111b8ae9 2021-05-26) running on x86_64-unknown-linux-gnu
note: compiler flags: --crate-type staticlib
query stack during panic:
#0 [mir_const_qualif] const checking `g`
#1 [mir_promoted] processing `g`
end of query stack
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.
Backtrace
error[E0658]: mutable references are not allowed in constant functions
--> mutant.rs:4:12
|
4 | const fn g(x: &mut [u32; 8]) {
| ^
|
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
error[E0625]: thread-local statics cannot be accessed at compile-time
--> mutant.rs:5:28
|
5 | std::mem::swap(x, &mut STATIC_VAR_2)
| ^^^^^^^^^^^^
thread 'rustc' panicked at 'tls access is checked in `Rvalue::ThreadLocalRef', compiler/rustc_mir/src/transform/check_consts/validation.rs:359:9
stack backtrace:
0: std::panicking::begin_panic
1: rustc_mir::transform::check_consts::validation::Validator::check_static
2: <rustc_mir::transform::check_consts::validation::Validator as rustc_middle::mir::visit::Visitor>::visit_rvalue
3: <rustc_mir::transform::check_consts::validation::Validator as rustc_middle::mir::visit::Visitor>::visit_statement
4: rustc_mir::transform::check_consts::validation::Validator::check_body
5: rustc_mir::transform::mir_const_qualif
6: core::ops::function::FnOnce::call_once
7: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
8: rustc_data_structures::stack::ensure_sufficient_stack
9: rustc_query_system::query::plumbing::force_query_with_job
10: rustc_query_system::query::plumbing::get_query_impl
11: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_const_qualif
12: rustc_mir::transform::mir_promoted
13: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
14: rustc_data_structures::stack::ensure_sufficient_stack
15: rustc_query_system::query::plumbing::force_query_with_job
16: rustc_query_system::query::plumbing::get_query_impl
17: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_promoted
18: rustc_mir::borrow_check::mir_borrowck
19: core::ops::function::FnOnce::call_once
20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
21: rustc_data_structures::stack::ensure_sufficient_stack
22: rustc_query_system::query::plumbing::force_query_with_job
23: rustc_query_system::query::plumbing::get_query_impl
24: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
25: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
26: rustc_interface::passes::analysis
27: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
28: rustc_data_structures::stack::ensure_sufficient_stack
29: rustc_query_system::query::plumbing::force_query_with_job
30: rustc_query_system::query::plumbing::get_query_impl
31: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
32: rustc_interface::passes::QueryContext::enter
33: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.54.0-nightly (9111b8ae9 2021-05-26) running on x86_64-unknown-linux-gnu
note: compiler flags: --crate-type staticlib
query stack during panic:
#0 [mir_const_qualif] const checking `g`
#1 [mir_promoted] processing `g`
#2 [mir_borrowck] borrow-checking `g`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.