Repository: rust
Issue: Some invalid cargo cache data leads to ICE
Labels: I-ICE,T-compiler,A-incr-comp,C-bug,S-needs-repro

I have code in a medium sized project (say, around 2k loc) I haven't been touching for several weeks.

It was compiling perfectly until i noticed a strange behavior in rust-analyzer. RA was giving me unused variables warnings for variables I was actually using.

When i tried to cargo run, rustc provided and ICE despite the code being in theory compiling.

This is due to somehow corrupted pre-built sources in my cargo cache, because deleting the debug directory fixes the issue - the compiler provides no more ice.

I will provide the stack trace but with no real guarantee this will help you more. I carefully kept the folder that produces the behavior available for further testing, should you need further information.
<details>
<summary>Version</summary>

```
rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7
```

</details>

<details>
<summary>Error output</summary>

```
thread 'rustc' panicked at compiler/rustc_hir/src/definitions.rs:389:13:
("Failed to convert DefPathHash", DefPathHash(Fingerprint(9813146037207872956, 15582269062064295123)))
stack backtrace:
   0:     0x7f4a499e8035 - std::backtrace_rs::backtrace::libunwind::trace::h1a07e5dba0da0cd2
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7f4a499e8035 - std::backtrace_rs::backtrace::trace_unsynchronized::h61b9b8394328c0bc
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f4a499e8035 - std::sys_common::backtrace::_print_fmt::h1c5e18b460934cff
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f4a499e8035 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1e1a1972118942ad
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f4a49a3729b - core::fmt::rt::Argument::fmt::h07af2b4071d536cd
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/fmt/rt.rs:165:63
   5:     0x7f4a49a3729b - core::fmt::write::hc090a2ffd6b28c4a
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/fmt/mod.rs:1157:21
   6:     0x7f4a499dcbdf - std::io::Write::write_fmt::h8898bac6ff039a23
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/io/mod.rs:1832:15
   7:     0x7f4a499e7e0e - std::sys_common::backtrace::_print::h4e80c5803d4ee35b
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f4a499e7e0e - std::sys_common::backtrace::print::ha96650907276675e
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f4a499ea779 - std::panicking::default_hook::{{closure}}::h215c2a0a8346e0e0
  10:     0x7f4a499ea4bd - std::panicking::default_hook::h207342be97478370
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:298:9
  11:     0x7f4a466891b7 - std[3c8ba8ebcf555201]::panicking::update_hook::<alloc[bfbae7e348dce413]::boxed::Box<rustc_driver_impl[c88438ade88661f4]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f4a499eae76 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::ha9c3bc81d312fd83
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/alloc/src/boxed.rs:2036:9
  13:     0x7f4a499eae76 - std::panicking::rust_panic_with_hook::hac8bdceee1e4fe2c
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:799:13
  14:     0x7f4a499eac24 - std::panicking::begin_panic_handler::{{closure}}::h00d785e82757ce3c
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:664:13
  15:     0x7f4a499e84f9 - std::sys_common::backtrace::__rust_end_short_backtrace::h1628d957bcd06996
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f4a499ea957 - rust_begin_unwind
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5
  17:     0x7f4a49a33763 - core::panicking::panic_fmt::hdc63834ffaaefae5
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:72:14
  18:     0x7f4a46723198 - <rustc_hir[809d8cc19d3b2ead]::definitions::Definitions>::local_def_path_hash_to_def_id::err
  19:     0x7f4a47a2cb70 - <rustc_middle[3ff731b746e7b038]::query::on_disk_cache::CacheDecoder as rustc_span[8c7415e9d33ddd75]::SpanDecoder>::decode_span
  20:     0x7f4a488d5b2c - <rustc_error_messages[d99a4cd37e6c3e46]::MultiSpan as rustc_serialize[f0de21e964e44561]::serialize::Decodable<rustc_middle[3ff731b746e7b038]::query::on_disk_cache::CacheDecoder>>::decode
  21:     0x7f4a47a2a7d1 - <rustc_middle[3ff731b746e7b038]::query::on_disk_cache::OnDiskCache>::load_side_effects
  22:     0x7f4a47a2985a - <rustc_query_system[4e189ce2c77124d]::dep_graph::graph::DepGraphData<rustc_middle[3ff731b746e7b038]::dep_graph::DepsType>>::try_mark_previous_green::<rustc_query_impl[a12402620de91e8]::plumbing::QueryCtxt>
  23:     0x7f4a47a291c4 - <rustc_query_system[4e189ce2c77124d]::dep_graph::graph::DepGraphData<rustc_middle[3ff731b746e7b038]::dep_graph::DepsType>>::try_mark_green::<rustc_query_impl[a12402620de91e8]::plumbing::QueryCtxt>
  24:     0x7f4a483821f7 - rustc_query_system[4e189ce2c77124d]::query::plumbing::ensure_must_run::<rustc_query_impl[a12402620de91e8]::DynamicConfig<rustc_query_system[4e189ce2c77124d]::query::caches::DefaultCache<rustc_span[8c7415e9d33ddd75]::def_id::LocalModDefId, rustc_middle[3ff731b746e7b038]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[a12402620de91e8]::plumbing::QueryCtxt>
  25:     0x7f4a48382716 - rustc_query_impl[a12402620de91e8]::query_impl::check_mod_type_wf::get_query_incr::__rust_end_short_backtrace
  26:     0x7f4a481ca1d0 - rustc_hir_analysis[46a17d8846b4335f]::check_crate
  27:     0x7f4a483890e0 - rustc_interface[640972162e3c086f]::passes::analysis
  28:     0x7f4a48388aef - rustc_query_impl[a12402620de91e8]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a12402620de91e8]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3ff731b746e7b038]::query::erase::Erased<[u8; 1usize]>>
  29:     0x7f4a48871e53 - rustc_query_system[4e189ce2c77124d]::query::plumbing::try_execute_query::<rustc_query_impl[a12402620de91e8]::DynamicConfig<rustc_query_system[4e189ce2c77124d]::query::caches::SingleCache<rustc_middle[3ff731b746e7b038]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a12402620de91e8]::plumbing::QueryCtxt, true>
  30:     0x7f4a48871a9c - rustc_query_impl[a12402620de91e8]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  31:     0x7f4a48583149 - rustc_interface[640972162e3c086f]::interface::run_compiler::<core[868bc93c3f2beb33]::result::Result<(), rustc_span[8c7415e9d33ddd75]::ErrorGuaranteed>, rustc_driver_impl[c88438ade88661f4]::run_compiler::{closure#0}>::{closure#1}
  32:     0x7f4a48540f8b - std[3c8ba8ebcf555201]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[640972162e3c086f]::util::run_in_thread_with_globals<rustc_interface[640972162e3c086f]::interface::run_compiler<core[868bc93c3f2beb33]::result::Result<(), rustc_span[8c7415e9d33ddd75]::ErrorGuaranteed>, rustc_driver_impl[c88438ade88661f4]::run_compiler::{closure#0}>::{closure#1}, core[868bc93c3f2beb33]::result::Result<(), rustc_span[8c7415e9d33ddd75]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[868bc93c3f2beb33]::result::Result<(), rustc_span[8c7415e9d33ddd75]::ErrorGuaranteed>>
  33:     0x7f4a48540d80 - <<std[3c8ba8ebcf555201]::thread::Builder>::spawn_unchecked_<rustc_interface[640972162e3c086f]::util::run_in_thread_with_globals<rustc_interface[640972162e3c086f]::interface::run_compiler<core[868bc93c3f2beb33]::result::Result<(), rustc_span[8c7415e9d33ddd75]::ErrorGuaranteed>, rustc_driver_impl[c88438ade88661f4]::run_compiler::{closure#0}>::{closure#1}, core[868bc93c3f2beb33]::result::Result<(), rustc_span[8c7415e9d33ddd75]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[868bc93c3f2beb33]::result::Result<(), rustc_span[8c7415e9d33ddd75]::ErrorGuaranteed>>::{closure#2} as core[868bc93c3f2beb33]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  34:     0x7f4a499f4cab - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h09e5a4c541afa800
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/alloc/src/boxed.rs:2022:9
  35:     0x7f4a499f4cab - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9c8b03c22f4e7026
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/alloc/src/boxed.rs:2022:9
  36:     0x7f4a499f4cab - std::sys::pal::unix::thread::Thread::new::thread_start::h522bc89a54da820a
                               at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys/pal/unix/thread.rs:108:17
  37:     0x7f4a436a8044 - start_thread
                               at ./nptl/pthread_create.c:442:8
  38:     0x7f4a4372861c - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  39:                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: rustc 1.79.0 (129f3b996 2024-06-10) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden
```

</details>

<details>
<sumary>Backtrace</summary>

```
stack backtrace:
   0: rust_begin_unwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:72:14
   2: <rustc_hir::definitions::Definitions>::local_def_path_hash_to_def_id::err
   3: <rustc_middle::query::on_disk_cache::CacheDecoder as rustc_span::SpanDecoder>::decode_span
   4: <rustc_error_messages::MultiSpan as rustc_serialize::serialize::Decodable<rustc_middle::query::on_disk_cache::CacheDecoder>>::decode
   5: <rustc_middle::query::on_disk_cache::OnDiskCache>::load_side_effects
   6: <rustc_query_system::dep_graph::graph::DepGraphData<rustc_middle::dep_graph::DepsType>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
   7: <rustc_query_system::dep_graph::graph::DepGraphData<rustc_middle::dep_graph::DepsType>>::try_mark_green::<rustc_query_impl::plumbing::QueryCtxt>
   8: rustc_query_system::query::plumbing::ensure_must_run::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalModDefId, rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt>
   9: rustc_hir_analysis::check_crate
  10: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  11: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```

</details>