Closed
Description
Code
(reduced)
struct AA {
pub data: [&usize]
}
impl AA {
const fn new() -> Self { }
}
static AA = AA::new();
fn main() { }
Original
//@ check-pass
pub struct AA {
pub data: [&usize],
}
impl AA {
pub const fn new() -> Self {
let mut res: AA = AA { data: [0; W+1] };
res.data[0] = 5;
res
}
}
static mut BB: AA = AA::new();
fn main() {
let ptr = unsafe { &mut BB };
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
for a in ptr.data.iter() {
println!("{}", a);
}
}
Meta
rustc --version --verbose
:
rustc 1.79.0-nightly (c9f8f3438 2024-03-27)
binary: rustc
commit-hash: c9f8f3438a8134a413aa5d4903e0196e44e37bbc
commit-date: 2024-03-27
host: x86_64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.2
Error output
error[E0106]: missing lifetime specifier
--> ./2A05930450229E90EA4891C95FF25ECB266E9736590D4E1A90761DAAF428CA86.rs:2:16
|
2 | pub data: [&usize]
| ^ expected named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
1 ~ struct AA<'a> {
2 ~ pub data: [&'a usize]
|
error: missing type for `static` item
--> ./2A05930450229E90EA4891C95FF25ECB266E9736590D4E1A90761DAAF428CA86.rs:9:10
|
9 | static AA = AA::new();
| ^ help: provide a type for the static variable: `: AA`
thread 'rustc' panicked at compiler/rustc_const_eval/src/const_eval/eval_queries.rs:53:5:
assertion failed: layout.is_sized()
Backtrace
thread 'rustc' panicked at compiler/rustc_const_eval/src/const_eval/eval_queries.rs:53:5:
assertion failed: layout.is_sized()
stack backtrace:
0: 0x10f1aee93 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8622fa9b8f01ae29
1: 0x10f1fccab - core::fmt::write::hfef1e936b89e9e59
2: 0x10f1a4fee - std::io::Write::write_fmt::h6a176982c498677c
3: 0x10f1aec81 - std::sys_common::backtrace::print::hc48f34eaebaf416f
4: 0x10f1b1ca9 - std::panicking::default_hook::{{closure}}::h3b950a0bf2b644e8
5: 0x10f1b1a10 - std::panicking::default_hook::he2d3412695f2d7b9
6: 0x117d4d97d - std[a2ca1e908c4c108d]::panicking::update_hook::<alloc[8ecff88a291c7d81]::boxed::Box<rustc_driver_impl[629facdbd27b12dd]::install_ice_hook::{closure#0}>>::{closure#0}
7: 0x10f1b27db - std::panicking::rust_panic_with_hook::h46c3037f3fbe8331
8: 0x10f1b20cc - std::panicking::begin_panic_handler::{{closure}}::h0477e56916a6d858
9: 0x10f1af369 - std::sys_common::backtrace::__rust_end_short_backtrace::hdac1cdd195496470
10: 0x10f1b1e36 - _rust_begin_unwind
11: 0x10f2178c5 - core::panicking::panic_fmt::hfd6b5bd1f65fa77f
12: 0x10f217997 - core::panicking::panic::h3b6d6fec553595b9
13: 0x117cd734e - rustc_const_eval[933ace3783df84a7]::const_eval::eval_queries::eval_static_initializer_provider
14: 0x119197a52 - rustc_query_impl[7ec918e69dd505e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7ec918e69dd505e]::query_impl::eval_static_initializer::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d0b008c68dae455]::query::erase::Erased<[u8; 16usize]>>
15: 0x11915150e - <rustc_query_impl[7ec918e69dd505e]::query_impl::eval_static_initializer::dynamic_query::{closure#2} as core[d5cb36deb602d542]::ops::function::FnOnce<(rustc_middle[d0b008c68dae455]::ty::context::TyCtxt, rustc_span[8dae231bb2118e0f]::def_id::DefId)>>::call_once
16: 0x118f5ece8 - rustc_query_system[40399bf5d3ff25f]::query::plumbing::try_execute_query::<rustc_query_impl[7ec918e69dd505e]::DynamicConfig<rustc_query_system[40399bf5d3ff25f]::query::caches::DefIdCache<rustc_middle[d0b008c68dae455]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[7ec918e69dd505e]::plumbing::QueryCtxt, false>
17: 0x1191c174d - rustc_query_impl[7ec918e69dd505e]::query_impl::eval_static_initializer::get_query_non_incr::__rust_end_short_backtrace
18: 0x117f85cab - <rustc_middle[d0b008c68dae455]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[2d5e89c8dacd405d]::check_crate::{closure#3}>::{closure#0}
19: 0x11808d24c - rustc_hir_analysis[2d5e89c8dacd405d]::check_crate
20: 0x118504c40 - rustc_interface[cb93122c76eb07a8]::passes::analysis
21: 0x119198eaa - rustc_query_impl[7ec918e69dd505e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7ec918e69dd505e]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d0b008c68dae455]::query::erase::Erased<[u8; 1usize]>>
22: 0x118f7fdde - rustc_query_system[40399bf5d3ff25f]::query::plumbing::try_execute_query::<rustc_query_impl[7ec918e69dd505e]::DynamicConfig<rustc_query_system[40399bf5d3ff25f]::query::caches::SingleCache<rustc_middle[d0b008c68dae455]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[7ec918e69dd505e]::plumbing::QueryCtxt, false>
23: 0x1191a3287 - rustc_query_impl[7ec918e69dd505e]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
24: 0x117cfb942 - <rustc_interface[cb93122c76eb07a8]::queries::QueryResult<&rustc_middle[d0b008c68dae455]::ty::context::GlobalCtxt>>::enter::<core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>, rustc_driver_impl[629facdbd27b12dd]::run_compiler::{closure#0}::{closure#1}::{closure#3}>
25: 0x117d5464b - rustc_interface[cb93122c76eb07a8]::interface::run_compiler::<core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>, rustc_driver_impl[629facdbd27b12dd]::run_compiler::{closure#0}>::{closure#0}
26: 0x117d43d36 - std[a2ca1e908c4c108d]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[cb93122c76eb07a8]::util::run_in_thread_with_globals<rustc_interface[cb93122c76eb07a8]::util::run_in_thread_pool_with_globals<rustc_interface[cb93122c76eb07a8]::interface::run_compiler<core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>, rustc_driver_impl[629facdbd27b12dd]::run_compiler::{closure#0}>::{closure#0}, core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>>::{closure#0}, core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>>
27: 0x117d5a3a8 - <<std[a2ca1e908c4c108d]::thread::Builder>::spawn_unchecked_<rustc_interface[cb93122c76eb07a8]::util::run_in_thread_with_globals<rustc_interface[cb93122c76eb07a8]::util::run_in_thread_pool_with_globals<rustc_interface[cb93122c76eb07a8]::interface::run_compiler<core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>, rustc_driver_impl[629facdbd27b12dd]::run_compiler::{closure#0}>::{closure#0}, core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>>::{closure#0}, core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>>::{closure#1} as core[d5cb36deb602d542]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
28: 0x10f1bbab9 - std::sys::pal::unix::thread::Thread::new::thread_start::h78e3183c2153313c
29: 0x7ff818270202 - __pthread_start
error: 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
query stack during panic:
#0 [eval_static_initializer] evaluating initializer of static `AA`
#1 [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 E0106`.
Metadata
Metadata
Assignees
Labels
Area: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Memory layout of typesCategory: This is a bug.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Status: This bug is tracked inside the repo by a `known-bug` test.Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.