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: mir build: scope: index out of bounds: the len is 0 but the index is 0 #125670

Open
matthiaskrgr opened this issue May 28, 2024 · 6 comments
Assignees
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. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

pub fn std() -> _ {
    return const {
        ({
            return ();
        })
    };
}

original:

#[non_exhaustive]
// run-pass

pub fn std() ->  _  { return  const {({ return  (
); }
)}; }

Version information

rustc 1.80.0-nightly (7717a306b 2024-05-28)
binary: rustc
commit-hash: 7717a306b2678ba9ece19b723c76a6b3a89ba931
commit-date: 2024-05-28
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

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

Program output

warning: unnecessary parentheses around block return value
 --> /tmp/icemaker_global_tempdir.JYB2yZP8eq2z/rustc_testrunner_tmpdir_reporting.ZJFueSdJhgaC/mvce.rs:3:9
  |
3 |         ({
  |         ^
4 |             return ();
5 |         })
  |          ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
3 ~         {
4 |             return ();
5 ~         }
  |

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

warning: unreachable expression
 --> /tmp/icemaker_global_tempdir.JYB2yZP8eq2z/rustc_testrunner_tmpdir_reporting.ZJFueSdJhgaC/mvce.rs:2:12
  |
2 |       return const {
  |  ____________^
3 | |         ({
4 | |             return ();
  | |             --------- any code following this expression is unreachable
5 | |         })
6 | |     };
  | |_____^ unreachable expression
  |
  = note: `#[warn(unreachable_code)]` on by default

error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
 --> /tmp/icemaker_global_tempdir.JYB2yZP8eq2z/rustc_testrunner_tmpdir_reporting.ZJFueSdJhgaC/mvce.rs:1:17
  |
1 | pub fn std() -> _ {
  |                 ^
  |                 |
  |                 not allowed in type signatures
  |                 help: replace with the correct return type: `()`

thread 'rustc' panicked at compiler/rustc_mir_build/src/build/scope.rs:639:58:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0:     0x7e0919f7bae5 - std::backtrace_rs::backtrace::libunwind::trace::h8e3ec5065424d28b
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7e0919f7bae5 - std::backtrace_rs::backtrace::trace_unsynchronized::h882cf49e59475dbc
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7e0919f7bae5 - std::sys_common::backtrace::_print_fmt::h2c337a2c4b83dc01
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7e0919f7bae5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5fad958b7140a660
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7e0919fcc5db - core::fmt::rt::Argument::fmt::h9f1efa968e340ff7
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/core/src/fmt/rt.rs:165:63
   5:     0x7e0919fcc5db - core::fmt::write::hc4341e028d4aa04e
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/core/src/fmt/mod.rs:1168:21
   6:     0x7e0919f7086f - std::io::Write::write_fmt::hf3dd4197197b5730
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/io/mod.rs:1835:15
   7:     0x7e0919f7b8be - std::sys_common::backtrace::_print::hee589e8f95e333af
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7e0919f7b8be - std::sys_common::backtrace::print::hc6a85e053c1c7334
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7e0919f7e2e9 - std::panicking::default_hook::{{closure}}::he62a1676f96fee54
  10:     0x7e0919f7e08a - std::panicking::default_hook::h2ceb904f12dea8be
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/panicking.rs:298:9
  11:     0x7e091678e6a0 - std[d6c1f98fb4e95ff7]::panicking::update_hook::<alloc[78b6f7e6bd40c475]::boxed::Box<rustc_driver_impl[c511ea10b869fcf7]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7e0919f7ea1b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hc5b72f85a4688529
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/alloc/src/boxed.rs:2077:9
  13:     0x7e0919f7ea1b - std::panicking::rust_panic_with_hook::h0a690364d46daaac
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/panicking.rs:799:13
  14:     0x7e0919f7e794 - std::panicking::begin_panic_handler::{{closure}}::h9c10c03249dd0030
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/panicking.rs:664:13
  15:     0x7e0919f7bfa9 - std::sys_common::backtrace::__rust_end_short_backtrace::h599802efea5774a9
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7e0919f7e4c7 - rust_begin_unwind
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/panicking.rs:652:5
  17:     0x7e0919fc8b73 - core::panicking::panic_fmt::h16f8f3f4aae78ff5
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/core/src/panicking.rs:72:14
  18:     0x7e0919fc8d87 - core::panicking::panic_bounds_check::h601b2b36c2e3745d
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/core/src/panicking.rs:274:5
  19:     0x7e0917e79f75 - <rustc_mir_build[9415bcb3f6b13a09]::build::Builder>::break_scope
  20:     0x7e0917e8c214 - <rustc_mir_build[9415bcb3f6b13a09]::build::Builder>::stmt_expr
  21:     0x7e0917e8c1c1 - <rustc_mir_build[9415bcb3f6b13a09]::build::Builder>::stmt_expr
  22:     0x7e09186f5a41 - <rustc_mir_build[9415bcb3f6b13a09]::build::Builder>::ast_block_stmts
  23:     0x7e09186f507b - <rustc_mir_build[9415bcb3f6b13a09]::build::Builder>::ast_block
  24:     0x7e0917e9e558 - <rustc_mir_build[9415bcb3f6b13a09]::build::Builder>::expr_into_dest
  25:     0x7e0917e961ea - <rustc_mir_build[9415bcb3f6b13a09]::build::Builder>::as_temp::{closure#0}
  26:     0x7e0917e9f6fb - <rustc_mir_build[9415bcb3f6b13a09]::build::Builder>::expr_into_dest
  27:     0x7e0917e9f972 - <rustc_mir_build[9415bcb3f6b13a09]::build::Builder>::expr_into_dest
  28:     0x7e09186f615c - <rustc_mir_build[9415bcb3f6b13a09]::build::Builder>::ast_block_stmts
  29:     0x7e09186f507b - <rustc_mir_build[9415bcb3f6b13a09]::build::Builder>::ast_block
  30:     0x7e0917e9e558 - <rustc_mir_build[9415bcb3f6b13a09]::build::Builder>::expr_into_dest
  31:     0x7e0917e9f972 - <rustc_mir_build[9415bcb3f6b13a09]::build::Builder>::expr_into_dest
  32:     0x7e0917e7481e - rustc_mir_build[9415bcb3f6b13a09]::build::mir_build
  33:     0x7e0917e712ce - rustc_query_impl[a43b8a3fae63a645]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a43b8a3fae63a645]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b8101328ceeb956a]::query::erase::Erased<[u8; 8usize]>>
  34:     0x7e0917dc212e - rustc_query_system[ef4de90281b6d444]::query::plumbing::try_execute_query::<rustc_query_impl[a43b8a3fae63a645]::DynamicConfig<rustc_query_system[ef4de90281b6d444]::query::caches::VecCache<rustc_span[8ae10af61471f323]::def_id::LocalDefId, rustc_middle[b8101328ceeb956a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[a43b8a3fae63a645]::plumbing::QueryCtxt, false>
  35:     0x7e0917dc1c4d - rustc_query_impl[a43b8a3fae63a645]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7e0917e657b0 - <rustc_mir_build[9415bcb3f6b13a09]::check_unsafety::UnsafetyVisitor>::visit_inner_body
  37:     0x7e09150a0d44 - <rustc_mir_build[9415bcb3f6b13a09]::check_unsafety::UnsafetyVisitor as rustc_middle[b8101328ceeb956a]::thir::visit::Visitor>::visit_expr
  38:     0x7e09150a0fd3 - <rustc_mir_build[9415bcb3f6b13a09]::check_unsafety::UnsafetyVisitor as rustc_middle[b8101328ceeb956a]::thir::visit::Visitor>::visit_expr
  39:     0x7e09150a0d44 - <rustc_mir_build[9415bcb3f6b13a09]::check_unsafety::UnsafetyVisitor as rustc_middle[b8101328ceeb956a]::thir::visit::Visitor>::visit_expr
  40:     0x7e09183ea835 - <rustc_mir_build[9415bcb3f6b13a09]::check_unsafety::UnsafetyVisitor as rustc_middle[b8101328ceeb956a]::thir::visit::Visitor>::visit_block
  41:     0x7e09150a2054 - <rustc_mir_build[9415bcb3f6b13a09]::check_unsafety::UnsafetyVisitor as rustc_middle[b8101328ceeb956a]::thir::visit::Visitor>::visit_expr
  42:     0x7e09150a0fd3 - <rustc_mir_build[9415bcb3f6b13a09]::check_unsafety::UnsafetyVisitor as rustc_middle[b8101328ceeb956a]::thir::visit::Visitor>::visit_expr
  43:     0x7e09150a0d44 - <rustc_mir_build[9415bcb3f6b13a09]::check_unsafety::UnsafetyVisitor as rustc_middle[b8101328ceeb956a]::thir::visit::Visitor>::visit_expr
  44:     0x7e0917e62a24 - rustc_mir_build[9415bcb3f6b13a09]::check_unsafety::check_unsafety
  45:     0x7e0917e624c7 - rustc_query_impl[a43b8a3fae63a645]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a43b8a3fae63a645]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b8101328ceeb956a]::query::erase::Erased<[u8; 0usize]>>
  46:     0x7e0917e615d4 - rustc_query_system[ef4de90281b6d444]::query::plumbing::try_execute_query::<rustc_query_impl[a43b8a3fae63a645]::DynamicConfig<rustc_query_system[ef4de90281b6d444]::query::caches::VecCache<rustc_span[8ae10af61471f323]::def_id::LocalDefId, rustc_middle[b8101328ceeb956a]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[a43b8a3fae63a645]::plumbing::QueryCtxt, false>
  47:     0x7e0917e61207 - rustc_query_impl[a43b8a3fae63a645]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  48:     0x7e0918568e5b - rustc_interface[3320d9bec8b3433a]::passes::analysis
  49:     0x7e0918567f5b - rustc_query_impl[a43b8a3fae63a645]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a43b8a3fae63a645]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b8101328ceeb956a]::query::erase::Erased<[u8; 1usize]>>
  50:     0x7e091899c225 - rustc_query_system[ef4de90281b6d444]::query::plumbing::try_execute_query::<rustc_query_impl[a43b8a3fae63a645]::DynamicConfig<rustc_query_system[ef4de90281b6d444]::query::caches::SingleCache<rustc_middle[b8101328ceeb956a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a43b8a3fae63a645]::plumbing::QueryCtxt, false>
  51:     0x7e091899bf8f - rustc_query_impl[a43b8a3fae63a645]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  52:     0x7e09187f9f5c - rustc_interface[3320d9bec8b3433a]::interface::run_compiler::<core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>, rustc_driver_impl[c511ea10b869fcf7]::run_compiler::{closure#0}>::{closure#1}
  53:     0x7e09187c0609 - std[d6c1f98fb4e95ff7]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[3320d9bec8b3433a]::util::run_in_thread_with_globals<rustc_interface[3320d9bec8b3433a]::util::run_in_thread_pool_with_globals<rustc_interface[3320d9bec8b3433a]::interface::run_compiler<core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>, rustc_driver_impl[c511ea10b869fcf7]::run_compiler::{closure#0}>::{closure#1}, core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>>::{closure#0}, core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>>
  54:     0x7e09187c03b2 - <<std[d6c1f98fb4e95ff7]::thread::Builder>::spawn_unchecked_<rustc_interface[3320d9bec8b3433a]::util::run_in_thread_with_globals<rustc_interface[3320d9bec8b3433a]::util::run_in_thread_pool_with_globals<rustc_interface[3320d9bec8b3433a]::interface::run_compiler<core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>, rustc_driver_impl[c511ea10b869fcf7]::run_compiler::{closure#0}>::{closure#1}, core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>>::{closure#0}, core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>>::{closure#2} as core[5e8023d66ded8339]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  55:     0x7e0919f889eb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha3f12f701ab217ba
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/alloc/src/boxed.rs:2063:9
  56:     0x7e0919f889eb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hbabc732018734ba3
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/alloc/src/boxed.rs:2063:9
  57:     0x7e0919f889eb - std::sys::pal::unix::thread::Thread::new::thread_start::h25b845304e0b166b
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/sys/pal/unix/thread.rs:108:17
  58:     0x7e09134aa1cf - <unknown>
  59:     0x7e091352b6ec - <unknown>
  60:                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: please make sure that you have updated to the latest nightly

note: rustc 1.80.0-nightly (7717a306b 2024-05-28) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_built] building MIR for `std::{constant#0}`
#1 [check_unsafety] unsafety-checking `std`
end of query stack
error: aborting due to 2 previous errors; 2 warnings emitted

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

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels May 28, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 28, 2024
@theemathas
Copy link
Contributor

theemathas commented May 29, 2024

Minimized:

fn foo() {
    const { return }
}

Variations that also cause ICEs of varying kinds:

fn foo() {
    'a: {
        const { break 'a }
    }
}
fn foo() {
    loop {
        const { break }
    }
}
fn foo() {
    'a: {
        const { continue 'a }
    }
}
fn foo() {
    loop {
        const { continue }
    }
}
async fn foo() {
    const { async {}.await }
}
fn foo() {
    let x = 1;
    const { &x };
}

@Noratrieb Noratrieb added I-prioritize Issue: Indicates that prioritization has been requested for this issue. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 29, 2024
@Noratrieb
Copy link
Member

cc @nbdd0121 that's pretty bad... the fix for that should probably be backported or maybe even delaying the stabilization for one release? no strong opinion.

@nbdd0121
Copy link
Contributor

nbdd0121 commented May 29, 2024

These examples all generate correct errors on beta (which contains inline const stablisation) but ICE on nightly. Looks like something else breaks these?

@nbdd0121
Copy link
Contributor

@rustbot label: +E-needs-bisection

@rustbot rustbot added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label May 29, 2024
@apiraino
Copy link
Contributor

I've tried bisecting a couple of them and they all both point to 7717a30 cc @oli-obk @nnethercote

@rustbot label -E-needs-bisection

@rustbot rustbot removed the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label May 29, 2024
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

Being easy to be triggered even if for now only on nightly.

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels May 29, 2024
@oli-obk oli-obk self-assigned this May 29, 2024
@workingjubilee workingjubilee added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label May 31, 2024
@matthiaskrgr matthiaskrgr added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jun 8, 2024
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. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

8 participants