Skip to content

ice: index out of bounds: the len is 0 but the index is 0 #120787

Closed
@matthiaskrgr

Description

@matthiaskrgr
Member

auto-reduced (treereduce-rust):

struct PrintOnDrop<'a>(&'a str);

impl Drop for PrintOnDrop<'_> {
    pub extern "C" fn valid_b() {}
}

original:

struct PrintOnDrop<'a>(&'a str);

impl Drop for PrintOnDrop<'_> {
    pub extern "C" fn valid_b() {
    unsafe {
        {
            {
                asm!("", options(noreturn));
            };
        };
    }
}
}

use std::collections::BTreeMap;
use std::iter::FromIterator;

fn main() {
    let s = String::from("Hello World!");
    let _map = BTreeMap::from_iter([((), PrintOnDrop(&s))]);
    drop(s); //~ ERROR cannot move out of `s` because it is borrowed
}

Version information

rustc 1.78.0-nightly (af88f7db5 2024-02-08)
binary: rustc
commit-hash: af88f7db51f6f2a1472f9279d7c7e7c822afff77
commit-date: 2024-02-08
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 17.0.6

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0449]: visibility qualifiers are not permitted here
 --> /tmp/icemaker_global_tempdir.KTcxw7O8nj5G/rustc_testrunner_tmpdir_reporting.ggV0pxQMrIHJ/mvce.rs:4:5
  |
4 |     pub extern "C" fn valid_b() {}
  |     ^^^
  |
  = note: trait items always share the visibility of their trait

error[E0407]: method `valid_b` is not a member of trait `Drop`
 --> /tmp/icemaker_global_tempdir.KTcxw7O8nj5G/rustc_testrunner_tmpdir_reporting.ggV0pxQMrIHJ/mvce.rs:4:5
  |
4 |     pub extern "C" fn valid_b() {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `Drop`

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.KTcxw7O8nj5G/rustc_testrunner_tmpdir_reporting.ggV0pxQMrIHJ/mvce.rs:5:2
  |
5 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.KTcxw7O8nj5G/rustc_testrunner_tmpdir_reporting.ggV0pxQMrIHJ/mvce.rs`

error[E0046]: not all trait items implemented, missing: `drop`
 --> /tmp/icemaker_global_tempdir.KTcxw7O8nj5G/rustc_testrunner_tmpdir_reporting.ggV0pxQMrIHJ/mvce.rs:3:1
  |
3 | impl Drop for PrintOnDrop<'_> {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `drop` in implementation
  |
  = help: implement the missing item: `fn drop(&mut self) { todo!() }`

thread 'rustc' panicked at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/compiler/rustc_middle/src/ty/sty.rs:1316:37:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0:     0x7fa0b0b8bdd6 - std::backtrace_rs::backtrace::libunwind::trace::hf92ca961e56825b0
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fa0b0b8bdd6 - std::backtrace_rs::backtrace::trace_unsynchronized::h23f341cc1a6c507f
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fa0b0b8bdd6 - std::sys_common::backtrace::_print_fmt::ha5a5ba44893edc7f
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7fa0b0b8bdd6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h667e6ba5a1d3724e
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fa0b0bde830 - core::fmt::rt::Argument::fmt::h06c91f49bef095fb
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/core/src/fmt/rt.rs:142:9
   5:     0x7fa0b0bde830 - core::fmt::write::h8e4b31b0aa81d13f
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/core/src/fmt/mod.rs:1120:17
   6:     0x7fa0b0b7f64f - std::io::Write::write_fmt::h4c479f5c53dfe78c
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/io/mod.rs:1854:15
   7:     0x7fa0b0b8bbb4 - std::sys_common::backtrace::_print::he414f5864df55ed1
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fa0b0b8bbb4 - std::sys_common::backtrace::print::h939e58bdcc61d57d
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fa0b0b8e947 - std::panicking::default_hook::{{closure}}::h244e48e05cd664b2
  10:     0x7fa0b0b8e6a9 - std::panicking::default_hook::hf842080c39497dac
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/panicking.rs:292:9
  11:     0x7fa0b39454ac - std[f801e042bca9681]::panicking::update_hook::<alloc[1377227f5558ef79]::boxed::Box<rustc_driver_impl[65af58b05c4f91ef]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fa0b0b8f096 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hee9c09a26ce84f59
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/alloc/src/boxed.rs:2029:9
  13:     0x7fa0b0b8f096 - std::panicking::rust_panic_with_hook::h83c20f9191a2a712
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/panicking.rs:785:13
  14:     0x7fa0b0b8ede2 - std::panicking::begin_panic_handler::{{closure}}::h9d287414fd341199
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/panicking.rs:659:13
  15:     0x7fa0b0b8c2d6 - std::sys_common::backtrace::__rust_end_short_backtrace::h6c439fc4b39e5f72
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7fa0b0b8eb34 - rust_begin_unwind
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/panicking.rs:647:5
  17:     0x7fa0b0bdaf35 - core::panicking::panic_fmt::h21d35284066b1c6e
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/core/src/panicking.rs:72:14
  18:     0x7fa0b0bdb172 - core::panicking::panic_bounds_check::h3b6d7c2964fb4600
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/core/src/panicking.rs:208:5
  19:     0x7fa0b4fe8344 - rustc_mir_build[1fe487e256cb3ff]::lints::check_drop_recursion
  20:     0x7fa0b2091449 - rustc_mir_transform[f04df7d082cb6ded]::mir_drops_elaborated_and_const_checked
  21:     0x7fa0b4de3675 - rustc_query_impl[5ca841c3c79670ea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5ca841c3c79670ea]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 8usize]>>
  22:     0x7fa0b4de38fa - rustc_query_system[125a8aa150dcabe3]::query::plumbing::try_execute_query::<rustc_query_impl[5ca841c3c79670ea]::DynamicConfig<rustc_query_system[125a8aa150dcabe3]::query::caches::VecCache<rustc_span[467c297c964200f6]::def_id::LocalDefId, rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[5ca841c3c79670ea]::plumbing::QueryCtxt, false>
  23:     0x7fa0b4de31d4 - rustc_query_impl[5ca841c3c79670ea]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  24:     0x7fa0b55d44ed - rustc_interface[c2746bee48761670]::passes::analysis
  25:     0x7fa0b55d3bdf - rustc_query_impl[5ca841c3c79670ea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5ca841c3c79670ea]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 1usize]>>
  26:     0x7fa0b58a17b2 - rustc_query_system[125a8aa150dcabe3]::query::plumbing::try_execute_query::<rustc_query_impl[5ca841c3c79670ea]::DynamicConfig<rustc_query_system[125a8aa150dcabe3]::query::caches::SingleCache<rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[5ca841c3c79670ea]::plumbing::QueryCtxt, false>
  27:     0x7fa0b58a1515 - rustc_query_impl[5ca841c3c79670ea]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7fa0b58e2436 - rustc_interface[c2746bee48761670]::interface::run_compiler::<core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>, rustc_driver_impl[65af58b05c4f91ef]::run_compiler::{closure#0}>::{closure#0}
  29:     0x7fa0b5560248 - std[f801e042bca9681]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c2746bee48761670]::util::run_in_thread_with_globals<rustc_interface[c2746bee48761670]::util::run_in_thread_pool_with_globals<rustc_interface[c2746bee48761670]::interface::run_compiler<core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>, rustc_driver_impl[65af58b05c4f91ef]::run_compiler::{closure#0}>::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>
  30:     0x7fa0b5560077 - <<std[f801e042bca9681]::thread::Builder>::spawn_unchecked_<rustc_interface[c2746bee48761670]::util::run_in_thread_with_globals<rustc_interface[c2746bee48761670]::util::run_in_thread_pool_with_globals<rustc_interface[c2746bee48761670]::interface::run_compiler<core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>, rustc_driver_impl[65af58b05c4f91ef]::run_compiler::{closure#0}>::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#1} as core[30be359c16b30868]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  31:     0x7fa0b0b98735 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h99757397e7c4fa77
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/alloc/src/boxed.rs:2015:9
  32:     0x7fa0b0b98735 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7e0e3d311e6447da
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/alloc/src/boxed.rs:2015:9
  33:     0x7fa0b0b98735 - std::sys::pal::unix::thread::Thread::new::thread_start::h0eb0f22e3002fa19
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys/pal/unix/thread.rs:108:17
  34:     0x7fa0b09839eb - <unknown>
  35:     0x7fa0b0a077cc - <unknown>
  36:                0x0 - <unknown>

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

note: rustc 1.78.0-nightly (af88f7db5 2024-02-08) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `<impl at /tmp/icemaker_global_tempdir.KTcxw7O8nj5G/rustc_testrunner_tmpdir_reporting.ggV0pxQMrIHJ/mvce.rs:3:1: 3:30>::valid_b`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0046, E0407, E0449, E0601.
For more information about an error, try `rustc --explain E0046`.

Activity

added
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-bugCategory: This is a bug.
on Feb 8, 2024
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Feb 8, 2024
added a commit that references this issue on Feb 8, 2024

Rollup merge of rust-lang#120801 - oli-obk:drop_recursion_ice, r=Nils…

ed52851
removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Feb 8, 2024
added a commit that references this issue on Feb 8, 2024
8863327
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @matthiaskrgr@fmease@rustbot

      Issue actions

        ice: `index out of bounds: the len is 0 but the index is 0` · Issue #120787 · rust-lang/rust