Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE with Drop in static block #81708

Closed
samueltardieu opened this issue Feb 3, 2021 · 1 comment · Fixed by #92207
Closed

ICE with Drop in static block #81708

samueltardieu opened this issue Feb 3, 2021 · 1 comment · Fixed by #92207
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-destructors Area: Destructors (`Drop`, …) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@samueltardieu
Copy link
Contributor

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,+I-ICE,+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

@samueltardieu samueltardieu added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 3, 2021
@jonas-schievink jonas-schievink added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-destructors Area: Destructors (`Drop`, …) I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 3, 2021
@camelid
Copy link
Member

camelid commented Feb 3, 2021

Assigning P-medium and removing I-prioritize as discussed in the prioritization working group.

@camelid camelid added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 3, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 5, 2021
@bors bors closed this as completed in 0604cf5 Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-destructors Area: Destructors (`Drop`, …) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants