Repository: rust
Issue: ICE: index out of bounds: the len is 0 but the index is 0
Labels: I-ICE,T-compiler,A-incr-comp,C-bug

Seems related to some other issues dealing with `on_disk_cache.rs`, but especially #83962 which was having trouble creating a MWE.

To reproduce:
1. create a new library crate `cargo new --lib bugtest`
2. create a tests folder and a new test file `a.rs`
3. put either a line comment or a block comment in `a.rs` and run `cargo test`
4. remove the comment and run `cargo test` again.

Nightly doesn't seem to have this problem, and if I delete `target` between builds, no error occurs.

### Code

```Rust
// src/lib.rs
#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
    }
}

// <crate>/tests/a.rs is empty, see note above
```


### Meta
`rustc --version --verbose`:
```
ustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: x86_64-apple-darwin
release: 1.51.0
LLVM version: 11.0.1
```

### Error output

```
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', compiler/rustc_middle/src/ty/query/on_disk_cache.rs:883:18
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
stack backtrace:
   0:        0x115c04394 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h18cc31b07c2f1a67
   1:        0x115c6884d - core::fmt::write::h24f8349e8e89c9af
   2:        0x115bf7226 - std::io::Write::write_fmt::hc54d7d6e95b15753
   3:        0x115c08219 - std::panicking::default_hook::{{closure}}::h11b550d560f5cc66
   4:        0x115c07da9 - std::panicking::default_hook::he168e99d1cf91c3c
   5:        0x10df69bb3 - rustc_driver::report_ice::h6aa3867cd8d12595
   6:        0x115c089fe - std::panicking::rust_panic_with_hook::hf87bfc4afef21ea6
   7:        0x115c08505 - std::panicking::begin_panic_handler::{{closure}}::h19ac9cd24a19b238
   8:        0x115c04838 - std::sys_common::backtrace::__rust_end_short_backtrace::h5fc3f41df3517232
   9:        0x115c0846a - _rust_begin_unwind
  10:        0x115c91e4f - core::panicking::panic_fmt::habd0855285375977
  11:        0x115c91e16 - core::panicking::panic_bounds_check::he5e20866df707d5e
  12:        0x111ea633e - rustc_middle::ty::query::on_disk_cache::<impl rustc_serialize::serialize::Decodable<rustc_middle::ty::query::on_disk_cache::CacheDecoder> for rustc_span::span_encoding::Span>::decode::h1e9997ba33fbc3f7
  13:        0x111fcd25c - rustc_middle::mir::_DERIVE_rustc_serialize_Decodable_D_FOR_SourceInfo::<impl rustc_serialize::serialize::Decodable<__D> for rustc_middle::mir::SourceInfo>::decode::haf221a4927ffd30d
  14:        0x111fd5ea6 - rustc_middle::mir::_DERIVE_rustc_serialize_Decodable_D_FOR_Statement::<impl rustc_serialize::serialize::Decodable<__D> for rustc_middle::mir::Statement>::decode::he1d0b173f8ef1a3c
  15:        0x11240b525 - rustc_serialize::serialize::Decoder::read_seq::h01887d60b8f67867
  16:        0x111fd8054 - rustc_middle::mir::_DERIVE_rustc_serialize_Decodable_D_FOR_BasicBlockData::<impl rustc_serialize::serialize::Decodable<__D> for rustc_middle::mir::BasicBlockData>::decode::h2afc8b38166d1a38
  17:        0x112410ea5 - rustc_serialize::serialize::Decoder::read_seq::hb9483adbceaa49e4
  18:        0x111fdb1c6 - rustc_middle::mir::_DERIVE_rustc_serialize_Decodable_D_FOR_Body::<impl rustc_serialize::serialize::Decodable<__D> for rustc_middle::mir::Body>::decode::h985284e2e2ddaad9
  19:        0x112444514 - rustc_middle::ty::query::on_disk_cache::OnDiskCache::try_load_query_result::h6443a34ca18c5fc5
  20:        0x1121610af - rustc_query_system::query::plumbing::load_from_disk_and_cache_in_memory::h35169eb6410a502f
  21:        0x111e5c410 - rustc_data_structures::stack::ensure_sufficient_stack::h8d3b48667ef06544
  22:        0x11205f681 - rustc_query_system::query::plumbing::get_query_impl::h2b4f706333e688e3
  23:        0x11225eaa5 - rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::instance_mir::he0978bb281277c57
  24:        0x110e011ca - rustc_mir::monomorphize::collector::collect_neighbours::h47b37e5990f3afcb
  25:        0x110dfbb05 - rustc_mir::monomorphize::collector::collect_items_rec::hcd74c1707c6ec78f
  26:        0x111102b61 - rustc_session::utils::<impl rustc_session::session::Session>::time::ha1ee399cb3fe0f28
  27:        0x110dfaa07 - rustc_mir::monomorphize::collector::collect_crate_mono_items::h5114ef167d49c1b0
  28:        0x110f0bedf - rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items::h86a5e6b8450fe938
  29:        0x10e2b9ba5 - rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::collect_and_partition_mono_items>::compute::hdf730f7c751072f9
  30:        0x10e1ea32b - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::h05b3be785a67773f
  31:        0x10e344d2d - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::h7d3bad97b315fab8
  32:        0x10e27ad18 - rustc_data_structures::stack::ensure_sufficient_stack::h430578ba4edcc55b
  33:        0x10e2f93f0 - rustc_query_system::query::plumbing::force_query_with_job::he6798077e257fb76
  34:        0x10e2e416f - rustc_query_system::query::plumbing::get_query_impl::hba4bc5f0e0530e1e
  35:        0x10e2bbb99 - rustc_codegen_ssa::base::codegen_crate::hf174017302958f95
  36:        0x10e31df13 - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::hfb775c0bdadfb20b
  37:        0x10e12e89f - rustc_interface::passes::QueryContext::enter::hc7070429d8c5bd75
  38:        0x10e16e250 - rustc_interface::queries::Queries::ongoing_codegen::hbf5b16e7a7d51d8b
  39:        0x10df88c9e - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::hec3d8a4aa25044cd
  40:        0x10df6c954 - rustc_span::with_source_map::h615f5706a6fcb422
  41:        0x10df89d44 - rustc_interface::interface::create_compiler_and_run::h58c4a2a7d59da299
  42:        0x10df6da35 - rustc_span::with_session_globals::h64b26cdf111538e9
  43:        0x10df8b9de - std::sys_common::backtrace::__rust_begin_short_backtrace::hc81e03926779116c
  44:        0x10dfb1bc9 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hedc61e08ab686125
  45:        0x115c15c8d - std::sys::unix::thread::Thread::new::thread_start::ha736b2d9de7b4dbc
  46:     0x7fff20643950 - __pthread_start
```

</p>
</details>