Repository: rust
Issue: ICE: get_adt_def called on a non-ADT, caused by build caching issues
Labels: I-ICE,T-compiler,A-incr-comp,C-bug,S-needs-repro

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.

http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/

-->

### Code


See https://github.com/algbio/practical-omnitigs. Branch `sebschmi/ICE` The Rust code is in the subfolder `implementation`.

Run `cargo test` to reproduce.

I am sorry, but I am not able to provide a minimal example at the moment.

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: x86_64-unknown-linux-gnu
release: 1.51.0
LLVM version: 11.0.1
```

### Full error output

<details><summary><strong>Backtrace</strong></summary>
<p>

```
error: internal compiler error: compiler/rustc_metadata/src/rmeta/decoder.rs:838:18: get_adt_def called on a non-ADT DefId(21:855 ~ traitgraph[39ee]::walks::VecNodeWalk)

thread 'rustc' panicked at 'Box<Any>', /rustc/2fd73fabe469357a12c2c974c140f67e7cdd76d0/library/std/src/panic.rs:59:5
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_metadata::rmeta::decoder::<impl rustc_metadata::creader::CrateMetadataRef>::get_adt_def
   8: rustc_metadata::rmeta::decoder::cstore_impl::provide_extern::adt_def
   9: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  10: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  11: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  12: rustc_data_structures::stack::ensure_sufficient_stack
  13: rustc_query_system::query::plumbing::force_query_with_job
  14: rustc_query_system::query::plumbing::force_query_impl
  15: rustc_middle::dep_graph::dep_node::dep_kind::adt_def::force_from_dep_node
  16: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  17: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  18: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  19: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  20: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  21: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  22: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_green_and_read
  23: rustc_data_structures::stack::ensure_sufficient_stack
  24: rustc_query_system::query::plumbing::get_query_impl
  25: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation
  26: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation_no_overflow
  27: rustc_trait_selection::traits::fulfill::FulfillProcessor::process_trait_obligation
  28: rustc_trait_selection::traits::fulfill::FulfillProcessor::progress_changed_obligations
  29: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_where_possible
  30: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_all_or_error
  31: rustc_trait_selection::traits::codegen::drain_fulfillment_cx_or_panic
  32: rustc_infer::infer::InferCtxtBuilder::enter
  33: rustc_trait_selection::traits::codegen::codegen_fulfill_obligation
  34: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::codegen_fulfill_obligation>::compute
  35: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  36: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  37: rustc_data_structures::stack::ensure_sufficient_stack
  38: rustc_query_system::query::plumbing::force_query_with_job
  39: rustc_query_system::query::plumbing::get_query_impl
  40: rustc_ty_utils::instance::inner_resolve_instance
  41: rustc_ty_utils::instance::resolve_instance
  42: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::resolve_instance>::compute
  43: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  44: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  45: rustc_data_structures::stack::ensure_sufficient_stack
  46: rustc_query_system::query::plumbing::force_query_with_job
  47: rustc_query_system::query::plumbing::get_query_impl
  48: rustc_middle::ty::instance::Instance::resolve_opt_const_arg
  49: rustc_middle::ty::instance::Instance::resolve
  50: <rustc_mir::monomorphize::collector::MirNeighborCollector as rustc_middle::mir::visit::Visitor>::visit_terminator
  51: rustc_mir::monomorphize::collector::collect_neighbours
  52: rustc_mir::monomorphize::collector::collect_items_rec
  53: rustc_mir::monomorphize::collector::collect_items_rec
  54: rustc_mir::monomorphize::collector::collect_items_rec
  55: rustc_mir::monomorphize::collector::collect_items_rec
  56: rustc_mir::monomorphize::collector::collect_items_rec
  57: rustc_mir::monomorphize::collector::collect_items_rec
  58: rustc_mir::monomorphize::collector::collect_items_rec
  59: rustc_mir::monomorphize::collector::collect_items_rec
  60: rustc_session::utils::<impl rustc_session::session::Session>::time
  61: rustc_mir::monomorphize::collector::collect_crate_mono_items
  62: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  63: 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
  64: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  65: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  66: rustc_data_structures::stack::ensure_sufficient_stack
  67: rustc_query_system::query::plumbing::force_query_with_job
  68: rustc_query_system::query::plumbing::get_query_impl
  69: rustc_codegen_ssa::base::codegen_crate
  70: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  71: rustc_session::utils::<impl rustc_session::session::Session>::time
  72: rustc_interface::passes::QueryContext::enter
  73: rustc_interface::queries::Queries::ongoing_codegen
  74: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  75: rustc_span::with_source_map
  76: rustc_interface::interface::create_compiler_and_run
  77: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: 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.51.0 (2fd73fabe 2021-03-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [adt_def] computing ADT definition for `traitgraph::walks::VecNodeWalk`
#1 [evaluate_obligation] evaluating trait selection obligation `std::iter::Map<std::iter::Filter<std::vec::IntoIter<unitigs::NodeUnitig<traitgraph::implementation::petgraph_impl::petgraph::Graph<(), (), traitgraph::implementation::petgraph_impl::petgraph::Directed, usize>>>, [closure@omnitigs/src/macrotigs/macronodes/strongly_connected_macronode_algorithm.rs:14:21: 18:14]>, fn(unitigs::NodeUnitig<traitgraph::implementation::petgraph_impl::petgraph::Graph<(), (), traitgraph::implementation::petgraph_impl::petgraph::Directed, usize>>) -> std::vec::Vec<<traitgraph::implementation::petgraph_impl::petgraph::Graph<(), (), traitgraph::implementation::petgraph_impl::petgraph::Directed, usize> as traitgraph::interface::GraphBase>::NodeIndex> {unitigs::NodeUnitig::<traitgraph::implementation::petgraph_impl::petgraph::Graph<(), (), traitgraph::implementation::petgraph_impl::petgraph::Directed, usize>>::into_node_walk}>: std::vec::source_iter_marker::SourceIterMarker`
#2 [codegen_fulfill_obligation] checking if `std::vec::spec_from_iter::SpecFromIter` fulfills its obligations
#3 [resolve_instance] resolving instance `<std::vec::Vec<std::vec::Vec<traitgraph::index::NodeIndex<usize>>> as std::vec::spec_from_iter::SpecFromIter<std::vec::Vec<traitgraph::index::NodeIndex<usize>>, std::iter::Map<std::iter::Filter<std::vec::IntoIter<unitigs::NodeUnitig<traitgraph::implementation::petgraph_impl::petgraph::Graph<(), (), traitgraph::implementation::petgraph_impl::petgraph::Directed, usize>>>, [closure@omnitigs/src/macrotigs/macronodes/strongly_connected_macronode_algorithm.rs:14:21: 18:14]>, fn(unitigs::NodeUnitig<traitgraph::implementation::petgraph_impl::petgraph::Graph<(), (), traitgraph::implementation::petgraph_impl::petgraph::Directed, usize>>) -> std::vec::Vec<<traitgraph::implementation::petgraph_impl::petgraph::Graph<(), (), traitgraph::implementation::petgraph_impl::petgraph::Directed, usize> as traitgraph::interface::GraphBase>::NodeIndex> {unitigs::NodeUnitig::<traitgraph::implementation::petgraph_impl::petgraph::Graph<(), (), traitgraph::implementation::petgraph_impl::petgraph::Directed, usize>>::into_node_walk}>>>::from_iter`
#4 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error; 2 warnings emitted

error: could not compile `omnitigs`

To learn more, run the command again with --verbose.
```

</p>
</details>

## What I tried

`cargo update` as of today updated the dependencies to a state that seem to circumvent the ICE.

Without the cargo update, using beta the ICE does not occur.

```
cargo 1.52.0-beta (90691f2bf 2021-03-16)
release: 1.52.0
commit-hash: 90691f2bfe9a50291a98983b1ed2feab51d5ca55
commit-date: 2021-03-16
```

Also without the cargo update, using nightly the ICE does not occur.

```
cargo 1.52.0-nightly (90691f2bf 2021-03-16)
release: 1.52.0
commit-hash: 90691f2bfe9a50291a98983b1ed2feab51d5ca55
commit-date: 2021-03-16
```

## What solved it

Deleting the target folder (after reverting the cargo update) fixed the ICE. I could then run `cargo test` again and no ICE occurred.

I might have clicked the test button too fast in my IDE while debugging, so possibly cargo was run concurrently.