Rust: ICE 'index out of bounds: the len is 0 but the index is 0', src/librustc_typeck/check/pat.rs:729:23

Created on 24 Sep 2019  路  9Comments  路  Source: rust-lang/rust

commit that introduced ICE: https://github.com/najamelan/pharos/commit/fa9b467ad928d4c1b42cef9637e44915e816ab82

The ICE happens on cargo check.
The most fundamental change here I imagine is introducing continue inside the match...

Backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', src/librustc_typeck/check/pat.rs:729:23
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:76
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:60
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1030
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1412
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:64
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:196
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:210
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:477
  12: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:380
  13: rust_begin_unwind
             at src/libstd/panicking.rs:307
  14: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  15: core::panicking::panic_bounds_check
             at src/libcore/panicking.rs:61
  16: rustc_typeck::check::pat::<impl rustc_typeck::check::FnCtxt>::check_pat_tuple_struct
  17: rustc_typeck::check::pat::<impl rustc_typeck::check::FnCtxt>::check_pat
  18: rustc_typeck::check::pat::<impl rustc_typeck::check::FnCtxt>::check_pat_tuple_struct
  19: rustc_typeck::check::pat::<impl rustc_typeck::check::FnCtxt>::check_pat
  20: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  21: rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt>::check_match
  22: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  23: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  24: rustc_typeck::check::FnCtxt::check_block_with_expected
  25: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  26: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  27: rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt>::check_match
  28: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  29: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  30: rustc_typeck::check::FnCtxt::check_block_with_expected
  31: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  32: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  33: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_meets_expectation_or_error
  34: rustc_typeck::check::FnCtxt::check_stmt
  35: rustc_typeck::check::FnCtxt::check_block_with_expected
  36: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  37: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  38: rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt>::check_match
  39: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  40: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  41: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  42: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  43: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_meets_expectation_or_error
  44: rustc_typeck::check::FnCtxt::check_stmt
  45: rustc_typeck::check::FnCtxt::check_block_with_expected
  46: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  47: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  48: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  49: rustc_typeck::check::check_fn
  50: rustc::ty::context::GlobalCtxt::enter_local
  51: rustc_typeck::check::typeck_tables_of
  52: rustc::ty::query::__query_compute::typeck_tables_of
  53: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
  54: rustc::dep_graph::graph::DepGraph::with_task_impl
  55: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  56: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  57: rustc_typeck::check::typeck_item_bodies
  58: rustc::ty::query::__query_compute::typeck_item_bodies
  59: rustc::dep_graph::graph::DepGraph::with_task_impl
  60: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  61: rustc::util::common::time
  62: rustc_typeck::check_crate
  63: rustc_interface::passes::analysis
  64: rustc::ty::query::__query_compute::analysis
  65: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  66: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  67: rustc_interface::passes::create_global_ctxt::{{closure}}
  68: rustc_interface::interface::run_compiler_in_existing_thread_pool
  69: std::thread::local::LocalKey<T>::with
  70: scoped_tls::ScopedKey<T>::set
  71: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.39.0-nightly (66bf391c3 2019-09-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib

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

query stack during panic:
#0 [typeck_tables_of] processing `<pharos::Pharos<Event> as futures_sink::Sink<Event>>::poll_flush`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack

A-diagnostics A-suggestion-diagnostics C-bug E-easy I-ICE T-compiler regression-from-stable-to-nightly

Most helpful comment

Minimal reproducer:

struct A(());

fn main() {
    let A() = A(());
}

Problem was introduced in https://github.com/rust-lang/rust/pull/64619.

Specifically the line: https://github.com/rust-lang/rust/blob/6ef275e6c3cb1384ec78128eceeb4963ff788dca/src/librustc_typeck/check/pat.rs#L729
is the problem... Seems we neglected to account for the nullary tuple case (()). The fix is to account for the lack of any elements in deciding what spans to use.

All 9 comments

Can reproduce on the current nightly (rustc 1.39.0-nightly (66bf391c3 2019-09-23)), but not on rustc 1.39.0-nightly (9b91b9c10 2019-08-26), so it's a regression.

Ok, this tries to eliminate stuff, but it doesn't fix the ICE: https://github.com/najamelan/pharos/commit/8b1db4ceca552428940acf4c96096c8b04682f82

Removing the match fixes the ICE.

Minimal reproducer:

struct A(());

fn main() {
    let A() = A(());
}

Problem was introduced in https://github.com/rust-lang/rust/pull/64619.

Specifically the line: https://github.com/rust-lang/rust/blob/6ef275e6c3cb1384ec78128eceeb4963ff788dca/src/librustc_typeck/check/pat.rs#L729
is the problem... Seems we neglected to account for the nullary tuple case (()). The fix is to account for the lack of any elements in deciding what spans to use.

cc @estebank @sam09

Can we use cargo-bisect-rustc to narrow this down to a specific PR?

NM

@Centril I see you self-assigned, just add && !subpats.is_empty() to the if expr.

@Centril In case you haven't started, I can help with this.

Investigating a possibly better solution than @estebank's for the zero case, I'll let you know how it pans out.

Was this page helpful?
0 / 5 - 0 ratings