rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.91k stars 12.52k forks source link

ICE: `elem.index() < self.domain_size` #125155

Closed matthiaskrgr closed 2 months ago

matthiaskrgr commented 4 months ago

auto-reduced (treereduce-rust):

enum NestedEnum {
    First,
    Second,
    Third
}
enum Enum {
    Variant2(Option<*mut &'a &'b ()>)
}

fn foo(x: Enum) -> isize {
    match x {
      Enum::Variant2(NestedEnum::Third) => 4,  
    }
}

original:

#![allow(dead_code)]

enum NestedEnum {
    First,
    Second,
    Third
}
enum Enum {
    Variant1(bool),
    Variant2(Option<*mut &'a &'b ()>)
}

#[inline(never)]
fn foo(x: Enum) -> isize {
    match x {
        Enum::Variant1(true) => 1,
        Enum::Variant1(false) => 2,
        Enum::Variant2(NestedEnum::Second) => 3,
        Enum::Variant2(NestedEnum::Third) => 4,
        Enum::Variant2(NestedEnum::First) => 5
    }
}

fn main() {
    assert_eq!(foo(Enum::Variant2(NestedEnum::Third)), 4);
}

Version information

rustc 1.80.0-nightly (9e7aff794 2024-05-15)
binary: rustc
commit-hash: 9e7aff794539aa040362f4424eb29207449ffce0
commit-date: 2024-05-15
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4

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

Program output

``` error: expected identifier, found `,` --> /tmp/icemaker_global_tempdir.atr7tKB0tvNE/rustc_testrunner_tmpdir_reporting.a4Uxzxxnly6f/mvce.rs:9:5 | 9 | , | ^ | | | expected identifier | help: remove this comma error[E0261]: use of undeclared lifetime name `'a` --> /tmp/icemaker_global_tempdir.atr7tKB0tvNE/rustc_testrunner_tmpdir_reporting.a4Uxzxxnly6f/mvce.rs:10:27 | 8 | enum Enum { | - help: consider introducing lifetime `'a` here: `<'a>` 9 | , 10 | Variant2(Option<*mut &'a &'b ()>) | ^^ undeclared lifetime error[E0261]: use of undeclared lifetime name `'b` --> /tmp/icemaker_global_tempdir.atr7tKB0tvNE/rustc_testrunner_tmpdir_reporting.a4Uxzxxnly6f/mvce.rs:10:31 | 8 | enum Enum { | - help: consider introducing lifetime `'b` here: `<'b>` 9 | , 10 | Variant2(Option<*mut &'a &'b ()>) | ^^ undeclared lifetime error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.atr7tKB0tvNE/rustc_testrunner_tmpdir_reporting.a4Uxzxxnly6f/mvce.rs:22:2 | 22 | } | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.atr7tKB0tvNE/rustc_testrunner_tmpdir_reporting.a4Uxzxxnly6f/mvce.rs` thread 'rustc' panicked at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/compiler/rustc_index/src/bit_set.rs:188:9: assertion failed: elem.index() < self.domain_size stack backtrace: 0: 0x7507130fee55 - std::backtrace_rs::backtrace::libunwind::trace::hc82148572bca43ce at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5 1: 0x7507130fee55 - std::backtrace_rs::backtrace::trace_unsynchronized::h9b6c0021060334e8 at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7507130fee55 - std::sys_common::backtrace::_print_fmt::hdf50e160c2606d9a at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/std/src/sys_common/backtrace.rs:68:5 3: 0x7507130fee55 - ::fmt::hd89105eb919743fa at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/std/src/sys_common/backtrace.rs:44:22 4: 0x75071314e16b - core::fmt::rt::Argument::fmt::h299039627f9699b8 at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/core/src/fmt/rt.rs:165:63 5: 0x75071314e16b - core::fmt::write::h90d4bcf0308a6921 at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/core/src/fmt/mod.rs:1169:21 6: 0x7507130f3b3f - std::io::Write::write_fmt::h971d4bf5135c0400 at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/std/src/io/mod.rs:1835:15 7: 0x7507130fec2e - std::sys_common::backtrace::_print::h0249ba9e007e0890 at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7507130fec2e - std::sys_common::backtrace::print::h512af02446eaf912 at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/std/src/sys_common/backtrace.rs:34:9 9: 0x750713101649 - std::panicking::default_hook::{{closure}}::hd7eed3dbeb3b0e1b 10: 0x75071310138d - std::panicking::default_hook::hc22637f42e887b27 at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/std/src/panicking.rs:298:9 11: 0x75070faf4d5f - std[e1f444a3457101b2]::panicking::update_hook::>::{closure#0} 12: 0x750713101d7b - as core::ops::function::Fn>::call::h53851f315593fb6e at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/alloc/src/boxed.rs:2036:9 13: 0x750713101d7b - std::panicking::rust_panic_with_hook::h5e0b74345c48df96 at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/std/src/panicking.rs:799:13 14: 0x750713101abb - std::panicking::begin_panic_handler::{{closure}}::h35a2f90e39b3450a at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/std/src/panicking.rs:656:13 15: 0x7507130ff319 - std::sys_common::backtrace::__rust_end_short_backtrace::hc74b426b89ea2072 at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/std/src/sys_common/backtrace.rs:171:18 16: 0x750713101827 - rust_begin_unwind at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/std/src/panicking.rs:652:5 17: 0x75071314a733 - core::panicking::panic_fmt::h64193357920b31af at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/core/src/panicking.rs:72:14 18: 0x75071314a7dc - core::panicking::panic::hd8eed21f3f9250e7 at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/core/src/panicking.rs:146:5 19: 0x750711533c1b - rustc_pattern_analysis[51b46f04f23eb7fd]::usefulness::compute_exhaustiveness_and_usefulness::::{closure#0} 20: 0x75071152f314 - rustc_pattern_analysis[51b46f04f23eb7fd]::usefulness::compute_exhaustiveness_and_usefulness::::{closure#0} 21: 0x75071153da54 - rustc_pattern_analysis[51b46f04f23eb7fd]::analyze_match 22: 0x75070e3d5869 - ::visit_expr 23: 0x75070e3d4d8d - ::visit_expr 24: 0x75070e3d5c64 - ::visit_expr 25: 0x75070e3d4d8d - ::visit_expr 26: 0x75071114470c - rustc_mir_build[36a8aa01da2a74cf]::thir::pattern::check_match::check_match 27: 0x7507111442df - rustc_query_impl[e4f4655505b9e0b]::plumbing::__rust_begin_short_backtrace::> 28: 0x750711142387 - rustc_query_system[3dc3927fb89859b0]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[e4f4655505b9e0b]::plumbing::QueryCtxt, false> 29: 0x750711142015 - rustc_query_impl[e4f4655505b9e0b]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace 30: 0x75071114d5cb - rustc_mir_build[36a8aa01da2a74cf]::build::mir_build 31: 0x75071114cc8e - rustc_query_impl[e4f4655505b9e0b]::plumbing::__rust_begin_short_backtrace::> 32: 0x7507115511f1 - rustc_query_system[3dc3927fb89859b0]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[e4f4655505b9e0b]::plumbing::QueryCtxt, false> 33: 0x750711550d0c - rustc_query_impl[e4f4655505b9e0b]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace 34: 0x75071113e5dc - rustc_mir_build[36a8aa01da2a74cf]::check_unsafety::check_unsafety 35: 0x75071113e36f - rustc_query_impl[e4f4655505b9e0b]::plumbing::__rust_begin_short_backtrace::> 36: 0x75071113d3dd - rustc_query_system[3dc3927fb89859b0]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[e4f4655505b9e0b]::plumbing::QueryCtxt, false> 37: 0x75071113d097 - rustc_query_impl[e4f4655505b9e0b]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace 38: 0x75071199a31b - rustc_interface[bf6b16ed275f9a93]::passes::analysis 39: 0x75071199941b - rustc_query_impl[e4f4655505b9e0b]::plumbing::__rust_begin_short_backtrace::> 40: 0x750711baef65 - rustc_query_system[3dc3927fb89859b0]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[e4f4655505b9e0b]::plumbing::QueryCtxt, false> 41: 0x750711baecc9 - rustc_query_impl[e4f4655505b9e0b]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 42: 0x750711a33e8e - rustc_interface[bf6b16ed275f9a93]::interface::run_compiler::, rustc_driver_impl[5e1c2d2058911521]::run_compiler::{closure#0}>::{closure#1} 43: 0x750711a1f4c9 - std[e1f444a3457101b2]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[5e1c2d2058911521]::run_compiler::{closure#0}>::{closure#1}, core[621fd6879f29e550]::result::Result<(), rustc_span[22bf4ef945b61209]::ErrorGuaranteed>>::{closure#0}, core[621fd6879f29e550]::result::Result<(), rustc_span[22bf4ef945b61209]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[621fd6879f29e550]::result::Result<(), rustc_span[22bf4ef945b61209]::ErrorGuaranteed>> 44: 0x750711a1f276 - <::spawn_unchecked_, rustc_driver_impl[5e1c2d2058911521]::run_compiler::{closure#0}>::{closure#1}, core[621fd6879f29e550]::result::Result<(), rustc_span[22bf4ef945b61209]::ErrorGuaranteed>>::{closure#0}, core[621fd6879f29e550]::result::Result<(), rustc_span[22bf4ef945b61209]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[621fd6879f29e550]::result::Result<(), rustc_span[22bf4ef945b61209]::ErrorGuaranteed>>::{closure#2} as core[621fd6879f29e550]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 45: 0x75071310bc1b - as core::ops::function::FnOnce>::call_once::h3f48e858c823da76 at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/alloc/src/boxed.rs:2022:9 46: 0x75071310bc1b - as core::ops::function::FnOnce>::call_once::he41c381165ad67aa at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/alloc/src/boxed.rs:2022:9 47: 0x75071310bc1b - std::sys::pal::unix::thread::Thread::new::thread_start::hed17c0eaf3bcb9d0 at /rustc/9e7aff794539aa040362f4424eb29207449ffce0/library/std/src/sys/pal/unix/thread.rs:108:17 48: 0x75070c8a955a - 49: 0x75070c926a3c - 50: 0x0 - 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 (9e7aff794 2024-05-15) running on x86_64-unknown-linux-gnu query stack during panic: #0 [check_match] match-checking `foo` #1 [mir_built] building MIR for `foo` end of query stack error: aborting due to 4 previous errors Some errors have detailed explanations: E0261, E0601. For more information about an error, try `rustc --explain E0261`. ```

matthiaskrgr commented 4 months ago

bisects to #122749

theemathas commented 3 months ago

Minimized (kinda):

enum NestedEnum {
    First,
    Second
}

enum Wrap<'a> {
    Wrapped(&'a ())
}

struct Thing(Wrap<'a>);

fn foo(x: Thing) {
    match x {
        Thing(NestedEnum::Second) => {},  
    }
}

The ICE occurs only when the match arm pattern uses the nth variant of NestedEnum, where n is greater than the number of variants in Wrap.