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 'index out of bounds: the len is 0 but the index is 0', src/librustc_typeck/check/pat.rs:729:23 #64744

Closed
najamelan opened this issue Sep 24, 2019 · 9 comments · Fixed by #64748 or #64751
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@najamelan
Copy link
Contributor

najamelan commented Sep 24, 2019

commit that introduced ICE: najamelan/pharos@fa9b467

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/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/git.luolix.top-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

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-async-await Area: Async & Await labels Sep 24, 2019
@jonas-schievink
Copy link
Contributor

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

@najamelan
Copy link
Contributor Author

najamelan commented Sep 24, 2019

Ok, this tries to eliminate stuff, but it doesn't fix the ICE: najamelan/pharos@8b1db4c

Removing the match fixes the ICE.

@Centril
Copy link
Contributor

Centril commented Sep 24, 2019

Minimal reproducer:

struct A(());

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

Problem was introduced in #64619.

Specifically the line:

vec![(subpats[0].span.shrink_to_lo(), "(".to_string()),

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.

@Centril
Copy link
Contributor

Centril commented Sep 24, 2019

cc @estebank @sam09

@jonas-schievink jonas-schievink added the A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` label Sep 24, 2019
@Centril Centril added A-diagnostics Area: Messages for errors, warnings, and lints and removed A-async-await Area: Async & Await labels Sep 24, 2019
@estebank estebank added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Sep 24, 2019
@nikomatsakis
Copy link
Contributor

nikomatsakis commented Sep 24, 2019

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

NM

@Centril Centril self-assigned this Sep 24, 2019
@estebank
Copy link
Contributor

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

@sam09
Copy link
Contributor

sam09 commented Sep 24, 2019

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

@Centril
Copy link
Contributor

Centril commented Sep 24, 2019

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

@Centril
Copy link
Contributor

Centril commented Sep 24, 2019

Fixed in #64748.

Centril added a commit to Centril/rust that referenced this issue Sep 24, 2019
bors added a commit that referenced this issue Sep 24, 2019
Rollup of 16 pull requests

Successful merges:

 - #63356 (Issue#63183: Add fs::read_dir() and ReadDir warning about iterator order + example)
 - #63934 (Fix coherence checking for impl trait in type aliases)
 - #64016 (Streamline `Compiler`)
 - #64296 (Document the unstable iter_order_by library feature)
 - #64443 (rustdoc: general cleanup)
 - #64622 (Add a cycle detector for generic `Graph`s and `mir::Body`s)
 - #64689 (Refactor macro by example)
 - #64698 (Recover on `const X = 42;` and infer type + Error Stash API)
 - #64702 (Remove unused dependencies)
 - #64717 (update mem::discriminant test to use assert_eq and assert_ne over comparison operators)
 - #64720 ( remove rtp.rs, and move rtpSpawn and RTP_ID_ERROR to libc)
 - #64721 (Fixed issue from #64447)
 - #64725 (fix one typo)
 - #64737 (fix several issues in String docs)
 - #64742 (relnotes: make compatibility section more sterile and fix rustc version)
 - #64748 (Fix #64744. Account for the Zero sub-pattern case.)

Failed merges:

r? @ghost
@bors bors closed this as completed in 7b71abd Sep 25, 2019
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this issue Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
6 participants