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: thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', compiler/rustc_abi/src/lib.rs:1195:59 #113326

Closed
Mari-W opened this issue Jul 4, 2023 · 3 comments · Fixed by #116801
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. 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.

Comments

@Mari-W
Copy link

Mari-W commented Jul 4, 2023

Code

#![allow(incomplete_features)]
#![feature(const_trait_impl)]
#![feature(const_closures)]
#![feature(const_refs_to_cell)]
#![feature(type_alias_impl_trait)]

pub type Diff = impl ~const std::marker::Destruct + ~const Fn(usize) -> usize;

pub const fn lift(n: usize) -> Diff {
    const move |m: usize| m + n
}

pub const fn reify(n: Diff) -> usize {
    n(0)
}

pub const fn add(
    n: Diff,
    m: Diff,
) -> Diff {
    const move |x: usize| m(n(x))
}

Meta

rustc --version --verbose:

rustc 1.72.0-nightly (0ab38e95b 2023-07-03)
binary: rustc
commit-hash: 0ab38e95bb1cbf0bd038d359bdecbfa501f003a7
commit-date: 2023-07-03
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5

Error output

could not compile `unnamed-lib` (lib)
Backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/compiler/rustc_abi/src/lib.rs:1195:59
stack backtrace:
   0:     0x7ff77b4ffac1 - std::backtrace_rs::backtrace::libunwind::trace::h468530b9ed459a5e
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7ff77b4ffac1 - std::backtrace_rs::backtrace::trace_unsynchronized::h1a2d5b62e76fd25f
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ff77b4ffac1 - std::sys_common::backtrace::_print_fmt::h260037bf2065d399
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7ff77b4ffac1 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd7fc81831607cf60
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ff77b565dcf - core::fmt::rt::Argument::fmt::h01afab03bee30eeb
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/core/src/fmt/rt.rs:138:9
   5:     0x7ff77b565dcf - core::fmt::write::h83c42ba3ca76c4aa
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/core/src/fmt/mod.rs:1094:21
   6:     0x7ff77b4f2407 - std::io::Write::write_fmt::h2430223c04b84a0f
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/io/mod.rs:1714:15
   7:     0x7ff77b4ff8d5 - std::sys_common::backtrace::_print::h7c08448e622e2b58
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7ff77b4ff8d5 - std::sys_common::backtrace::print::h8f55173e6a80d5ad
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7ff77b5026b3 - std::panicking::default_hook::{{closure}}::heb93e2549b3b187f
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/panicking.rs:269:22
  10:     0x7ff77b502444 - std::panicking::default_hook::h915abe4b17644eca
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/panicking.rs:288:9
  11:     0x7ff77a2bf97b - <rustc_driver_impl[146e28695489c3b6]::install_ice_hook::{closure#0} as core[cc24119d2f561fcf]::ops::function::FnOnce<(&core[cc24119d2f561fcf]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  12:     0x7ff77b502ede - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h092e69b77f2ec5c7
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/alloc/src/boxed.rs:2024:9
  13:     0x7ff77b502ede - std::panicking::rust_panic_with_hook::ha1753497d761687d
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/panicking.rs:709:13
  14:     0x7ff77b502c67 - std::panicking::begin_panic_handler::{{closure}}::h94f1c0e8e158230f
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/panicking.rs:597:13
  15:     0x7ff77b4fff26 - std::sys_common::backtrace::__rust_end_short_backtrace::h8f0ed1c8ce3bb685
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/sys_common/backtrace.rs:151:18
  16:     0x7ff77b5029b2 - rust_begin_unwind
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/panicking.rs:593:5
  17:     0x7ff77b562023 - core::panicking::panic_fmt::hd946f96734ef59b2
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/core/src/panicking.rs:67:14
  18:     0x7ff77b562182 - core::panicking::panic_bounds_check::h9afa51f49491098b
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/core/src/panicking.rs:162:5
  19:     0x7ff7793089cd - <rustc_const_eval[d9bc543eca73fa59]::interpret::eval_context::InterpCx<rustc_mir_transform[5aa385746779acac]::const_prop::ConstPropMachine>>::place_field
  20:     0x7ff7792f567d - <rustc_const_eval[d9bc543eca73fa59]::interpret::eval_context::InterpCx<rustc_mir_transform[5aa385746779acac]::const_prop::ConstPropMachine>>::eval_rvalue_into_place
  21:     0x7ff7792e71a7 - <rustc_mir_transform[5aa385746779acac]::const_prop_lint::ConstPropagator as rustc_middle[e56c0de64a470188]::mir::visit::Visitor>::visit_basic_block_data
  22:     0x7ff7792e1c62 - <rustc_mir_transform[5aa385746779acac]::const_prop_lint::ConstProp as rustc_mir_transform[5aa385746779acac]::pass_manager::MirLint>::run_lint
  23:     0x7ff778b0dab6 - rustc_mir_transform[5aa385746779acac]::mir_drops_elaborated_and_const_checked
  24:     0x7ff7782e194e - rustc_query_impl[5e6cc1cea09d293]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5e6cc1cea09d293]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e56c0de64a470188]::query::erase::Erased<[u8; 8usize]>>
  25:     0x7ff7782e191e - <rustc_query_impl[5e6cc1cea09d293]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2} as core[cc24119d2f561fcf]::ops::function::FnOnce<(rustc_middle[e56c0de64a470188]::ty::context::TyCtxt, rustc_span[5b039f53ab17f7a0]::def_id::LocalDefId)>>::call_once
  26:     0x7ff7793b8dcd - rustc_query_system[3139d05a59a2b03]::query::plumbing::try_execute_query::<rustc_query_impl[5e6cc1cea09d293]::DynamicConfig<rustc_query_system[3139d05a59a2b03]::query::caches::VecCache<rustc_span[5b039f53ab17f7a0]::def_id::LocalDefId, rustc_middle[e56c0de64a470188]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[5e6cc1cea09d293]::plumbing::QueryCtxt, true>
  27:     0x7ff779c26049 - rustc_query_impl[5e6cc1cea09d293]::query_impl::mir_drops_elaborated_and_const_checked::get_query_incr::__rust_end_short_backtrace
  28:     0x7ff7796e2009 - <rustc_session[1d3a915322f525ec]::session::Session>::time::<(), rustc_interface[a6e5b8ea369f438f]::passes::analysis::{closure#2}>
  29:     0x7ff7796dd815 - rustc_interface[a6e5b8ea369f438f]::passes::analysis
  30:     0x7ff77977f00a - rustc_query_impl[5e6cc1cea09d293]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5e6cc1cea09d293]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e56c0de64a470188]::query::erase::Erased<[u8; 1usize]>>
  31:     0x7ff77977eff9 - <rustc_query_impl[5e6cc1cea09d293]::query_impl::analysis::dynamic_query::{closure#2} as core[cc24119d2f561fcf]::ops::function::FnOnce<(rustc_middle[e56c0de64a470188]::ty::context::TyCtxt, ())>>::call_once
  32:     0x7ff779a7a23f - rustc_query_system[3139d05a59a2b03]::query::plumbing::try_execute_query::<rustc_query_impl[5e6cc1cea09d293]::DynamicConfig<rustc_query_system[3139d05a59a2b03]::query::caches::SingleCache<rustc_middle[e56c0de64a470188]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[5e6cc1cea09d293]::plumbing::QueryCtxt, true>
  33:     0x7ff779a79de4 - rustc_query_impl[5e6cc1cea09d293]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  34:     0x7ff779446bd5 - <rustc_middle[e56c0de64a470188]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[146e28695489c3b6]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[cc24119d2f561fcf]::result::Result<(), rustc_span[5b039f53ab17f7a0]::ErrorGuaranteed>>
  35:     0x7ff779446202 - <rustc_interface[a6e5b8ea369f438f]::interface::Compiler>::enter::<rustc_driver_impl[146e28695489c3b6]::run_compiler::{closure#1}::{closure#2}, core[cc24119d2f561fcf]::result::Result<core[cc24119d2f561fcf]::option::Option<rustc_interface[a6e5b8ea369f438f]::queries::Linker>, rustc_span[5b039f53ab17f7a0]::ErrorGuaranteed>>
  36:     0x7ff77943cd25 - rustc_span[5b039f53ab17f7a0]::set_source_map::<core[cc24119d2f561fcf]::result::Result<(), rustc_span[5b039f53ab17f7a0]::ErrorGuaranteed>, rustc_interface[a6e5b8ea369f438f]::interface::run_compiler<core[cc24119d2f561fcf]::result::Result<(), rustc_span[5b039f53ab17f7a0]::ErrorGuaranteed>, rustc_driver_impl[146e28695489c3b6]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  37:     0x7ff77943c146 - <scoped_tls[65afcd617045176b]::ScopedKey<rustc_span[5b039f53ab17f7a0]::SessionGlobals>>::set::<rustc_interface[a6e5b8ea369f438f]::interface::run_compiler<core[cc24119d2f561fcf]::result::Result<(), rustc_span[5b039f53ab17f7a0]::ErrorGuaranteed>, rustc_driver_impl[146e28695489c3b6]::run_compiler::{closure#1}>::{closure#0}, core[cc24119d2f561fcf]::result::Result<(), rustc_span[5b039f53ab17f7a0]::ErrorGuaranteed>>
  38:     0x7ff77943b70c - std[adcf6cea4a8307ac]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[a6e5b8ea369f438f]::util::run_in_thread_pool_with_globals<rustc_interface[a6e5b8ea369f438f]::interface::run_compiler<core[cc24119d2f561fcf]::result::Result<(), rustc_span[5b039f53ab17f7a0]::ErrorGuaranteed>, rustc_driver_impl[146e28695489c3b6]::run_compiler::{closure#1}>::{closure#0}, core[cc24119d2f561fcf]::result::Result<(), rustc_span[5b039f53ab17f7a0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[cc24119d2f561fcf]::result::Result<(), rustc_span[5b039f53ab17f7a0]::ErrorGuaranteed>>
  39:     0x7ff779b094fe - <<std[adcf6cea4a8307ac]::thread::Builder>::spawn_unchecked_<rustc_interface[a6e5b8ea369f438f]::util::run_in_thread_pool_with_globals<rustc_interface[a6e5b8ea369f438f]::interface::run_compiler<core[cc24119d2f561fcf]::result::Result<(), rustc_span[5b039f53ab17f7a0]::ErrorGuaranteed>, rustc_driver_impl[146e28695489c3b6]::run_compiler::{closure#1}>::{closure#0}, core[cc24119d2f561fcf]::result::Result<(), rustc_span[5b039f53ab17f7a0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[cc24119d2f561fcf]::result::Result<(), rustc_span[5b039f53ab17f7a0]::ErrorGuaranteed>>::{closure#1} as core[cc24119d2f561fcf]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  40:     0x7ff77b50d355 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hfb71eecc96172696
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/alloc/src/boxed.rs:2010:9
  41:     0x7ff77b50d355 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha18d3bb12fa77a3c
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/alloc/src/boxed.rs:2010:9
  42:     0x7ff77b50d355 - std::sys::unix::thread::Thread::new::thread_start::h827451defd93f6e7
                               at /rustc/0ab38e95bb1cbf0bd038d359bdecbfa501f003a7/library/std/src/sys/unix/thread.rs:108:17
  43:     0x7ff776c94b43 - start_thread
                               at ./nptl/pthread_create.c:442:8
  44:     0x7ff776d26a00 - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  45:                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.72.0-nightly (0ab38e95b 2023-07-03) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C linker=x86_64-linux-gnu-gcc -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `add`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `unnamed-lib` (lib)

@Mari-W Mari-W 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 Jul 4, 2023
@clubby789 clubby789 changed the title internal compiler error: index out of bounds ICE: thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', compiler/rustc_abi/src/lib.rs:1195:59 Jul 9, 2023
@clubby789
Copy link
Contributor

clubby789 commented Jul 9, 2023

error: internal compiler error: compiler/rustc_const_eval/src/interpret/eval_context.rs:390:21: expected type differs from actual type.
                                expected: usize
                                actual: [closure@../poc.rs:10:5: 10:26]
  --> ../poc.rs:17:1
   |
17 | / pub const fn add(
18 | |     n: Diff,
19 | |     m: Diff,
20 | | ) -> Diff {
   | |_________^

Can be reduced to

#![feature(type_alias_impl_trait)]

pub type Diff = impl Fn(usize) -> usize;

pub fn lift(n: usize) -> Diff {
    move |m: usize| m + n
}

pub fn add(
    f: Diff,
) -> Diff {
    move |x: usize| f(x)
}

fn main() {}

@clubby789
Copy link
Contributor

pub fn lift() -> Diff {
    |_: usize |loop {}
}

Also causes the out of bounds panic (len is 0 but the index is 0), but not the earlier type mismatch ICE

@JohnTitor
Copy link
Member

Triage: Fixed on the latest nightly, marked as E-needs-test
@rustbot labels: +E-needs-test

@rustbot rustbot added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 10, 2023
rust-cloud-vms bot pushed a commit to clubby789/rust that referenced this issue Oct 16, 2023
@bors bors closed this as completed in 75efc4f Oct 25, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 25, 2023
Rollup merge of rust-lang#116801 - clubby789:issue-113326-test, r=compiler-errors

Add test for 113326

Closes rust-lang#113326
Bisecting points to rust-lang#113636 as the fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants