Repository: rust
Issue: Incremental compilation ICE: Found unstable fingerprints for predicates_of(dicom_core[4803]::value::DicomValueType)
Labels: I-ICE,T-compiler,A-incr-comp,C-bug

I triggered ICE through incremental compilation (tracker issue #84970) while working on [DICOM-rs](https://github.com/Enet4/dicom-rs). This could be a similar problem to #88318. Unlike what was reported in #84341, `predicates_of` was called on a trait in the same workspace.

<!--
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

I was unable to reproduce this a second time in a fresh working space. When the ICE occurred, I saved the state of the project in [this branch](https://github.com/Enet4/dicom-rs/tree/rustc_ice_bug/parser/encoder-update-text-codec). Then I tried to recall all the steps I had done since the previous revision, around this order:

1. Deprecate `dicom_encoding::text::DynamicTextCodec`
2. Deprecate `dicom_encoding::text::SpecificCharacterSet::codec`
3. Add an `impl TextCodec for SpecificCharacterSet`, methods implemented by matching on self and picking the right text codec type.
4. Add associated const `SpecificCharacterSet::GB18030 = SpecificCharacterSet::Gb18030`
5. Rename the enum variant `GB18030` to `Gb18030`, update the name in the rest of the module
6. Remove the associated const (I had changed my mind regarding its usefulness)
7. Remove uses of `.codec()` in `dicom_encoding::text::tests`

But tracing these steps again did not trigger any ICE. Rust-analyzer was running, which suddenly started failing all checking requests. The ICE only occurs on `cargo check`.

### Meta

Latest stable. `cargo +beta check` yielded no ICE, but it could just be the consequence of checking the code from scratch.

<!--
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.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: x86_64-unknown-linux-gnu
release: 1.54.0
LLVM version: 12.0.1
```

### Error output

```
    Checking dicom-parser v0.4.0 (/home/enet4/dev/dicom-rs/parser)
warning: use of deprecated associated function `dicom_encoding::text::SpecificCharacterSet::codec`: this value is a codec in itself
   --> ul/src/pdu/reader.rs:129:10
    |
129 |         .codec()
    |          ^^^^^
    |
    = note: `#[warn(deprecated)]` on by default

warning: 1 warning emitted

warning: use of deprecated type alias `dicom_encoding::text::DynamicTextCodec`: Use `SpecificCharacterSet` instead
  --> parser/src/stateful/decode.rs:12:70
   |
12 |     validate_da, validate_dt, validate_tm, DefaultCharacterSetCodec, DynamicTextCodec,
   |                                                                      ^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(deprecated)]` on by default

warning: use of deprecated type alias `dicom_encoding::text::DynamicTextCodec`: Use `SpecificCharacterSet` instead
   --> parser/src/stateful/decode.rs:746:42
    |
746 | impl<S, D, BD> StatefulDecoder<D, S, BD, DynamicTextCodec>
    |                                          ^^^^^^^^^^^^^^^^

warning: use of deprecated type alias `dicom_encoding::text::DynamicTextCodec`: Use `SpecificCharacterSet` instead
   --> parser/src/stateful/decode.rs:844:61
    |
844 | impl<D, S, BD> StatefulDecode for StatefulDecoder<D, S, BD, DynamicTextCodec>
    |                                                             ^^^^^^^^^^^^^^^^

warning: use of deprecated type alias `dicom_encoding::text::DynamicTextCodec`: Use `SpecificCharacterSet` instead
   --> parser/src/stateful/decode.rs:221:58
    |
221 | pub struct StatefulDecoder<D, S, BD = BasicDecoder, TC = DynamicTextCodec> {
    |                                                          ^^^^^^^^^^^^^^^^

error: internal compiler error: encountered incremental compilation error with predicates_of(dicom_core[4803]::value::DicomValueType)
  |
  = help: This is a known issue with the compiler. Run `cargo clean -p dicom_parser` or `cargo clean` to allow your project to compile
  = note: Please follow the instructions below to create a bug report with the provided information
  = note: See <https://github.com/rust-lang/rust/issues/84970> for more information

thread 'rustc' panicked at 'Found unstable fingerprints for predicates_of(dicom_core[4803]::value::DicomValueType): GenericPredicates { parent: None, predicates: [(Binder(TraitPredicate(<Self as dicom_core::header::HasLength>), []), /home/enet4/dev/dicom-rs/core/src/value/mod.rs:24:27: 24:36 (#0)), (Binder(TraitPredicate(<Self as dicom_core::value::DicomValueType>), []), /home/enet4/dev/dicom-rs/core/src/value/mod.rs:24:1: 35:2 (#0))] }', /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/compiler/rustc_query_system/src/query/plumbing.rs:620:9
note: run with `RUST_BACKTRACE=1` environment variable to display a 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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.54.0 (a178d0322 2021-07-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [predicates_of] computing predicates of `dicom_core::value::DicomValueType`
#1 [typeck] type-checking `dataset::<impl at parser/src/dataset/mod.rs:59:1: 66:2>::fmt`
end of query stack
error: aborting due to previous error; 4 warnings emitted

error: could not compile `dicom-parser`
```

<!--
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>

```
thread 'rustc' panicked at 'Found unstable fingerprints for predicates_of(dicom_core[4803]::value::DicomValueType): GenericPredicates { parent: None, predicates: [(Binder(TraitPredicate(<Self as dicom_core::header::HasLength>), []), /home/enet4/dev/dicom-rs/core/src/value/mod.rs:24:27: 24:36 (#0)), (Binder(TraitPredicate(<Self as dicom_core::value::DicomValueType>), []), /home/enet4/dev/dicom-rs/core/src/value/mod.rs:24:1: 35:2 (#0))] }', /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/compiler/rustc_query_system/src/query/plumbing.rs:620:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:515:5
   1: std::panicking::begin_panic_fmt
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:457:5
   2: rustc_query_system::query::plumbing::incremental_verify_ich
   3: rustc_query_system::query::plumbing::load_from_disk_and_cache_in_memory
   4: rustc_query_system::query::plumbing::get_query_impl
   5: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::predicates_of
   6: rustc_middle::ty::generics::GenericPredicates::instantiate_into
   7: rustc_middle::ty::generics::GenericPredicates::instantiate
   8: rustc_typeck::check::method::confirm::ConfirmContext::confirm
   9: rustc_typeck::check::method::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::lookup_method
  10: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  11: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  12: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  13: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  14: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
  15: <T as rustc_middle::ty::context::InternIteratorElement<T,R>>::intern_with
  16: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  17: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  18: rustc_typeck::check::_match::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::demand_scrutinee_type
  19: rustc_typeck::check::_match::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_match
  20: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  21: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  22: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  23: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  24: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_argument_types
  25: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::confirm_builtin_call
  26: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  27: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  28: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  29: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_argument_types
  30: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_method_argument_types
  31: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  32: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  33: rustc_typeck::check::_match::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_match
  34: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  35: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  36: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  37: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  38: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  39: rustc_typeck::check::check::check_fn
  40: rustc_typeck::check::inherited::InheritedBuilder::enter
  41: rustc_typeck::check::typeck
  42: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  43: rustc_data_structures::stack::ensure_sufficient_stack
  44: rustc_query_system::query::plumbing::force_query_with_job
  45: rustc_query_system::query::plumbing::get_query_impl
  46: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  47: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  48: rustc_typeck::check::typeck_item_bodies
  49: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  50: rustc_data_structures::stack::ensure_sufficient_stack
  51: rustc_query_system::query::plumbing::force_query_with_job
  52: rustc_query_system::query::plumbing::get_query_impl
  53: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
  54: rustc_session::utils::<impl rustc_session::session::Session>::time
  55: rustc_typeck::check_crate
  56: rustc_interface::passes::analysis
  57: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  58: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  59: rustc_query_system::dep_graph::graph::DepGraph<K>::with_eval_always_task
  60: rustc_data_structures::stack::ensure_sufficient_stack
  61: rustc_query_system::query::plumbing::force_query_with_job
  62: rustc_query_system::query::plumbing::get_query_impl
  63: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  64: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  65: rustc_span::with_source_map
  66: rustc_interface::interface::create_compiler_and_run
  67: scoped_tls::ScopedKey<T>::set
```
</p>
</details>

<details><summary><strong>Backtrace from rust-analyzer</strong></summary>
<p>

```
thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.70.0/src/lib.rs:2752:10
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:92:14
   2: core::panicking::panic_bounds_check
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:69:5
   3: <&chalk_ir::SubstFolder<I,A> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   6: hir_ty::infer::coerce::<impl hir_ty::infer::InferenceContext>::coerce_inner
   7: hir_ty::infer::coerce::<impl hir_ty::infer::InferenceContext>::coerce
   8: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::check_call_arguments
   9: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_method_call
  10: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  11: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  12: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_method_call
  13: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  14: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  15: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  16: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  17: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  18: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  19: hir_ty::infer::infer_query
  20: salsa::runtime::Runtime::execute_query_implementation
  21: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  22: salsa::derived::slot::Slot<Q,MP>::read
  23: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  24: <DB as hir_ty::db::HirDatabase>::infer_query
  25: hir_ty::db::infer_wait
  26: hir::semantics::SemanticsImpl::analyze_impl
  27: hir::semantics::SemanticsImpl::scope
  28: ide::inlay_hints::inlay_hints
  29: std::panicking::try
  30: rust_analyzer::handlers::handle_inlay_hints
  31: rust_analyzer::dispatch::RequestDispatcher::on::{{closure}}::{{closure}}
  32: <F as threadpool::FnBox>::call_box
```
</p>
</details>