Skip to content

ICE: mir build: scope: index out of bounds: the len is 0 but the index is 0 #125670

Closed

Description

@matthiaskrgr

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`.

Activity

  1. 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 May 28, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on May 28, 2024
  3. theemathas commented on May 29, 2024

    @theemathas
    Contributor

    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 };
    }
  4. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on May 29, 2024
  5. Noratrieb commented on May 29, 2024

    @Noratrieb
    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.

  6. nbdd0121 commented on May 29, 2024

    @nbdd0121
    Member

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

  7. nbdd0121 commented on May 29, 2024

    @nbdd0121
    Member

    @rustbot label: +E-needs-bisection

  8. added
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on May 29, 2024
  9. apiraino commented on May 29, 2024

    @apiraino
    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

  10. removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on May 29, 2024
  11. apiraino commented on May 29, 2024

    @apiraino
    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

  12. 1 remaining item

  13. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on May 29, 2024
  14. self-assigned this
    on May 29, 2024
  15. added
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    on May 31, 2024
  16. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Jun 8, 2024
  17. jieyouxu commented on Nov 13, 2024

    @jieyouxu
    Member

    P-high pre-triage: AFAICT this was fixed by #125918, none of these examples ICE on nightly or stable (1.82.0).

  18. jieyouxu commented on Nov 13, 2024

    @jieyouxu
    Member

    Oh wait I see, these simple examples don't have regression tests.

    EDIT: unassigning oli who's on vacation, marking this as E-easy for basic sanity tests for examples in #125670 (comment).

  19. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    on Nov 13, 2024
  20. Eclips4 commented on Nov 13, 2024

    @Eclips4
    Contributor

    @rustbot claim

  21. added a commit that references this issue on Nov 14, 2024
    18136cf
  22. added a commit that references this issue on Nov 14, 2024
    04c626b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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

    No branches or pull requests

    Issue actions