Repository: rust
Issue: rustdoc: ICE: synthetic auto trait impls: `unexpected result when selecting […] obligation`
Labels: T-rustdoc,I-ICE,T-compiler,C-bug,A-synthetic-impls,glacier,A-auto-traits

<!--
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
`rustdoc` crashes on the following code:

```Rust
pub trait Module {
    type Algebra;
}

pub trait ChainComplex {
    type Algebra;
    type Module: Module;
}

pub struct FreeModule<A> {
    foo: A,
}

impl<A> Module for FreeModule<A> {
    type Algebra = A;
}

pub trait FreeChainComplex:
    ChainComplex<Module = FreeModule<<Self as ChainComplex>::Algebra>>
{
}

pub struct ResolutionHomomorphism<CC1, CC2>
where
    CC1: FreeChainComplex<Algebra = CC2::Algebra>,
    CC2: FreeChainComplex,
{
    source: CC1,
    maps: CC2::Module,
}

pub struct SecondaryResolutionHomomorphism<
    CC1: FreeChainComplex,
    CC2: FreeChainComplex<Algebra = CC1::Algebra>,
> {
    underlying: ResolutionHomomorphism<CC1, CC2>,
}
```


### Meta
This crashes on both `1.54.0`, `1.56.0` and nightly (2021-11-29)

### Error output

```
thread 'rustc' panicked at 'Unexpected result when selecting SecondaryResolutionHomomorphism<CC1, CC2> Obligation(predicate=Binder(ProjectionPredicate(ProjectionTy { substs: [CC2], item_def_id: DefId(0:7 ~ ice[d87a]::ChainComplex::Module) }, _), []), depth=2)', compiler/rustc_trait_selection/src/traits/auto_trait.rs:773:33
```
<details><summary><strong>Backtrace</strong></summary>
<p>

```
stack backtrace:
   0: rust_begin_unwind
             at /rustc/6db0a0e9a4a2f55b1a85954e114ada0b45c32e45/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/6db0a0e9a4a2f55b1a85954e114ada0b45c32e45/library/core/src/panicking.rs:107:14
   2: <rustc_trait_selection::traits::auto_trait::AutoTraitFinder>::evaluate_nested_obligations::<alloc::vec::into_iter::IntoIter<rustc_infer::traits::Obligation<rustc_middle::ty::Predicate>>>
   3: <rustc_trait_selection::traits::auto_trait::AutoTraitFinder>::evaluate_predicates
   4: <rustdoc::clean::auto_trait::AutoTraitFinder>::generate_for_trait
   5: <alloc::vec::Vec<rustdoc::clean::types::Item> as alloc::vec::spec_from_iter::SpecFromIter<rustdoc::clean::types::Item, core::iter::adapters::filter_map::FilterMap<alloc::vec::into_iter::IntoIter<rustc_span::def_id::DefId>, <rustdoc::clean::auto_trait::AutoTraitFinder>::get_auto_trait_impls::{closure#0}>>>::from_iter
   6: <rustdoc::clean::auto_trait::AutoTraitFinder>::get_auto_trait_impls
   7: rustdoc::clean::utils::get_auto_trait_and_blanket_impls
   8: <rustdoc::passes::collect_trait_impls::SyntheticImplCollector as rustdoc::visit::DocVisitor>::visit_item
   9: <rustdoc::passes::collect_trait_impls::SyntheticImplCollector as rustdoc::visit::DocVisitor>::visit_item
  10: <rustdoc::passes::collect_trait_impls::SyntheticImplCollector as rustdoc::visit::DocVisitor>::visit_crate
  11: <rustc_session::session::Session>::time::<alloc::vec::Vec<rustdoc::clean::types::Item>, rustdoc::passes::collect_trait_impls::collect_trait_impls::{closure#0}>
  12: rustdoc::passes::collect_trait_impls::collect_trait_impls
  13: <rustc_session::session::Session>::time::<rustdoc::clean::types::Crate, rustdoc::core::run_global_ctxt::{closure#11}>
  14: rustdoc::core::run_global_ctxt
  15: <rustc_session::session::Session>::time::<(rustdoc::clean::types::Crate, rustdoc::config::RenderOptions, rustdoc::formats::cache::Cache), rustdoc::main_options::{closure#0}::{closure#0}::{closure#0}::{closure#0}>
  16: <rustc_interface::interface::Compiler>::enter::<rustdoc::main_options::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
  17: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustdoc::main_options::{closure#0}>::{closure#1}>
  18: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustdoc::main_options::{closure#0}>
  19: rustdoc::main_options
  20: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustdoc::main_args::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

error: Unrecognized option: 'crate-version'

error: could not document `ice`

Caused by:
  process didn't exit successfully: `rustdoc --edition=2018 --crate-type lib --crate-name ice src/lib.rs -o /tmp/ice/target/doc --error-format=json --json=diagnostic-rendered-ansi -C metadata=75642385eb1e00a4 -L dependency=/tmp/ice/target/debug/deps --crate-version 0.1.0` (exit status: 1)
```

</p>
</details>