Closed
Description
ICE in illegal code in static block, rustc stable/beta/nightly. Found and reduced by @regar42.
Code
static T: () = {
let test_arr: [String; 1];
test_arr[0] = String::new();
};
fn main() {
}
Meta
rustc --version --verbose
:
rustc 1.51.0-nightly (04caa632d 2021-01-30)
binary: rustc
commit-hash: 04caa632dd10c2bf64b69524c7f9c4c30a436877
commit-date: 2021-01-30
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly
LLVM version: 11.0.1
Also happens with
rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-unknown-linux-gnu
release: 1.49.0
Error output
error[E0493]: destructors cannot be evaluated at compile-time
--> t.rs:3:5
|
3 | test_arr[0] = String::new();
| ^^^^^^^^^^^
| |
| statics cannot evaluate destructors
| value is dropped here
error[E0493]: destructors cannot be evaluated at compile-time
--> t.rs:2:9
|
2 | let test_arr: [String; 1];
| ^^^^^^^^ statics cannot evaluate destructors
3 | test_arr[0] = String::new();
4 | };
| - value is dropped here
error[E0381]: use of possibly-uninitialized variable: `test_arr`
--> t.rs:3:5
|
3 | test_arr[0] = String::new();
| ^^^^^^^^^^^ use of possibly-uninitialized `test_arr`
error: internal compiler error: compiler/rustc_mir/src/transform/elaborate_drops.rs:316:25: drop of untracked, uninitialized value bb2, place _1[_3] (Parent(Some(mp1)))
--> t.rs:3:5
|
3 | test_arr[0] = String::new();
| ^^^^^^^^^^^
thread 'rustc' panicked at 'Box<Any>', /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/compiler/rustc_errors/src/lib.rs:904:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
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.51.0-nightly (04caa632d 2021-01-30) running on x86_64-unknown-linux-gnu
query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `T`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0381, E0493.
For more information about an error, try `rustc --explain E0381`.
Backtrace
0: std::panicking::begin_panic
1: rustc_errors::HandlerInner::span_bug
2: rustc_errors::Handler::span_bug
3: rustc_middle::ty::context::tls::with_opt
4: rustc_middle::util::bug::opt_span_bug_fmt
5: rustc_middle::util::bug::span_bug_fmt
6: <rustc_mir::transform::elaborate_drops::ElaborateDrops as rustc_mir::transform::MirPass>::run_pass
7: rustc_mir::transform::run_passes
8: rustc_mir::transform::run_post_borrowck_cleanup_passes
9: rustc_mir::transform::mir_drops_elaborated_and_const_checked
10: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_drops_elaborated_and_const_checked>::compute
11: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
12: rustc_data_structures::stack::ensure_sufficient_stack
13: rustc_query_system::query::plumbing::force_query_with_job
14: rustc_query_system::query::plumbing::get_query_impl
15: rustc_query_system::query::plumbing::ensure_query_impl
16: rustc_interface::passes::analysis
17: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
18: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
19: rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::{{closure}}
20: rustc_query_system::query::plumbing::force_query_with_job
21: rustc_query_system::query::plumbing::get_query_impl
22: rustc_interface::passes::QueryContext::enter
23: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
24: rustc_span::with_source_map
Metadata
Metadata
Assignees
Labels
Area: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Destructors (`Drop`, …)Category: This is a bug.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.ICE tracked in rust-lang/glacier.