Repository: rust
Issue: ICE: `rustc_specialization_trait` and circular associated type
Labels: I-ICE,T-compiler,A-specialization,C-bug,F-specialization,F-rustc_attrs,glacier,S-has-mcve,S-bug-has-test,T-types,requires-internal-features

### Code

[[Playground link]](https://play.rust-lang.org/?edition=2021&gist=dfeae3d7de9324a5f43e3937618e8857)

```Rust
#![feature(min_specialization, rustc_attrs)]

#[rustc_specialization_trait]
pub trait Trait {}

struct Struct
where
    Self: Iterator<Item = <Self as Iterator>::Item>, {}

impl Trait for Struct {}
```

### Meta

`rustc --version --verbose`:
```
rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-unknown-linux-gnu
release: 1.64.0
LLVM version: 14.0.6

rustc 1.65.0-beta.2 (e5da98475 2022-09-24)
binary: rustc
commit-hash: e5da98475e88b52384bac96923bba7cd45941d69
commit-date: 2022-09-24
host: x86_64-unknown-linux-gnu
release: 1.65.0-beta.2
LLVM version: 15.0.0

rustc 1.66.0-nightly (3f83906b3 2022-09-24)
binary: rustc
commit-hash: 3f83906b30798bf61513fa340524cebf6676f9db
commit-date: 2022-09-24
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.0
```

### Error output

```
   Compiling ice v0.0.0 (/home/ubuntu/dev/ice)
thread 'rustc' panicked at 'assertion failed: !obligations.needs_infer()', compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs:358:13

[Backtrace removed]

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.66.0-nightly (3f83906b3 2022-09-24) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [check_mod_impl_wf] checking that impls are well-formed in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: implied_outlives_bounds failed to solve all obligations
  --> src/lib.rs:10:1
   |
10 | impl Trait for Struct {}
   | ^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at compiler/rustc_trait_selection/src/traits/outlives_bounds.rs:63:31

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1530:13

[Backtrace removed]

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.66.0-nightly (3f83906b3 2022-09-24) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
thread panicked while panicking. aborting.
error: could not compile `ice`

Caused by:
  process didn't exit successfully: `rustc --crate-name ice --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=2cc8a57eb73b0fe5 -C extra-filename=-2cc8a57eb73b0fe5 --out-dir /home/ubuntu/dev/ice/target/debug/deps -C incremental=/home/ubuntu/dev/ice/target/debug/incremental -L dependency=/home/ubuntu/dev/ice/target/debug/deps` (signal: 6, SIGABRT: process abort signal)
```

<!--
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>

```
   Compiling ice v0.0.0 (/home/ubuntu/dev/ice)
thread 'rustc' panicked at 'assertion failed: !obligations.needs_infer()', compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs:358:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/std/src/panicking.rs:556:5
   1: core::panicking::panic_fmt
             at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/core/src/panicking.rs:142:14
   2: core::panicking::panic
             at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/core/src/panicking.rs:48:5
   3: <rustc_infer::infer::InferCtxtBuilder>::enter::<(), rustc_typeck::impl_wf_check::min_specialization::check_predicates::{closure#3}>
   4: rustc_typeck::impl_wf_check::min_specialization::check_min_specialization
   5: rustc_typeck::impl_wf_check::check_mod_impl_wf
   6: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId, ()>
   7: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, ()>>
   8: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::check_mod_impl_wf, rustc_query_impl::plumbing::QueryCtxt>
   9: <rustc_middle::hir::map::Map>::for_each_module::<rustc_typeck::check_crate::{closure#2}::{closure#0}::{closure#0}>
  10: <rustc_session::session::Session>::track_errors::<rustc_typeck::check_crate::{closure#2}, ()>
  11: rustc_typeck::check_crate
  12: rustc_interface::passes::analysis
  13: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  14: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorGuaranteed>>>
  15: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  16: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  17: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
  18: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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.66.0-nightly (3f83906b3 2022-09-24) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [check_mod_impl_wf] checking that impls are well-formed in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: implied_outlives_bounds failed to solve all obligations
  --> src/lib.rs:10:1
   |
10 | impl Trait for Struct {}
   | ^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at compiler/rustc_trait_selection/src/traits/outlives_bounds.rs:63:31

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1530:13
stack backtrace:
   0:     0x7f3a43cd1fc0 - std::backtrace_rs::backtrace::libunwind::trace::h83db09f97ba446e0
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x7f3a43cd1fc0 - std::backtrace_rs::backtrace::trace_unsynchronized::hbc692a375382599a
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f3a43cd1fc0 - std::sys_common::backtrace::_print_fmt::h5d9374f1dc540502
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f3a43cd1fc0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h678bc20029fef91d
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f3a43d2cdfe - core::fmt::write::h3ff59c1e0cfd7af2
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/core/src/fmt/mod.rs:1202:17
   5:     0x7f3a43cc2c05 - std::io::Write::write_fmt::h57bc84b9ab3e4292
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/std/src/io/mod.rs:1679:15
   6:     0x7f3a43cd4d43 - std::sys_common::backtrace::_print::h58613138e3b60a1b
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f3a43cd4d43 - std::sys_common::backtrace::print::h182e9bde2e8d07ea
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f3a43cd4d43 - std::panicking::default_hook::{{closure}}::h829771b46ce932f3
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/std/src/panicking.rs:267:22
   9:     0x7f3a43cd4a2f - std::panicking::default_hook::h167447d609e3453b
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/std/src/panicking.rs:286:9
  10:     0x7f3a4650c431 - <rustc_driver[615eae184240f2d1]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[d525c930f060fa4e]::ops::function::FnOnce<(&core[d525c930f060fa4e]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7f3a43cd557b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h8a7c5a65eb87446d
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/alloc/src/boxed.rs:1954:9
  12:     0x7f3a43cd557b - std::panicking::rust_panic_with_hook::haa7a7aef616e6ae8
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/std/src/panicking.rs:673:13
  13:     0x7f3a4761e931 - std[590eaa09bda9df92]::panicking::begin_panic::<rustc_errors[a92f92f3abe4e548]::ExplicitBug>::{closure#0}
  14:     0x7f3a4761e306 - std[590eaa09bda9df92]::sys_common::backtrace::__rust_end_short_backtrace::<std[590eaa09bda9df92]::panicking::begin_panic<rustc_errors[a92f92f3abe4e548]::ExplicitBug>::{closure#0}, !>
  15:     0x7f3a4761dfa6 - std[590eaa09bda9df92]::panicking::begin_panic::<rustc_errors[a92f92f3abe4e548]::ExplicitBug>
  16:     0x7f3a4761bd06 - std[590eaa09bda9df92]::panic::panic_any::<rustc_errors[a92f92f3abe4e548]::ExplicitBug>
  17:     0x7f3a46055338 - <rustc_errors[a92f92f3abe4e548]::HandlerInner as core[d525c930f060fa4e]::ops::drop::Drop>::drop
  18:     0x7f3a452da348 - core[d525c930f060fa4e]::ptr::drop_in_place::<rustc_session[c2bba8d08c637bfa]::parse::ParseSess>
  19:     0x7f3a452985c8 - <alloc[10be8beb537b5cb7]::rc::Rc<rustc_session[c2bba8d08c637bfa]::session::Session> as core[d525c930f060fa4e]::ops::drop::Drop>::drop
  20:     0x7f3a4529529d - core[d525c930f060fa4e]::ptr::drop_in_place::<rustc_interface[c48cc815669d5993]::interface::Compiler>
  21:     0x7f3a45293444 - rustc_interface[c48cc815669d5993]::interface::create_compiler_and_run::<core[d525c930f060fa4e]::result::Result<(), rustc_errors[a92f92f3abe4e548]::ErrorGuaranteed>, rustc_driver[615eae184240f2d1]::run_compiler::{closure#1}>
  22:     0x7f3a45290f41 - <scoped_tls[cad2a7494d31e12]::ScopedKey<rustc_span[199ab19abca3e97b]::SessionGlobals>>::set::<rustc_interface[c48cc815669d5993]::interface::run_compiler<core[d525c930f060fa4e]::result::Result<(), rustc_errors[a92f92f3abe4e548]::ErrorGuaranteed>, rustc_driver[615eae184240f2d1]::run_compiler::{closure#1}>::{closure#0}, core[d525c930f060fa4e]::result::Result<(), rustc_errors[a92f92f3abe4e548]::ErrorGuaranteed>>
  23:     0x7f3a45290c2f - std[590eaa09bda9df92]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c48cc815669d5993]::util::run_in_thread_pool_with_globals<rustc_interface[c48cc815669d5993]::interface::run_compiler<core[d525c930f060fa4e]::result::Result<(), rustc_errors[a92f92f3abe4e548]::ErrorGuaranteed>, rustc_driver[615eae184240f2d1]::run_compiler::{closure#1}>::{closure#0}, core[d525c930f060fa4e]::result::Result<(), rustc_errors[a92f92f3abe4e548]::ErrorGuaranteed>>::{closure#0}, core[d525c930f060fa4e]::result::Result<(), rustc_errors[a92f92f3abe4e548]::ErrorGuaranteed>>
  24:     0x7f3a46362ff0 - <<std[590eaa09bda9df92]::thread::Builder>::spawn_unchecked_<rustc_interface[c48cc815669d5993]::util::run_in_thread_pool_with_globals<rustc_interface[c48cc815669d5993]::interface::run_compiler<core[d525c930f060fa4e]::result::Result<(), rustc_errors[a92f92f3abe4e548]::ErrorGuaranteed>, rustc_driver[615eae184240f2d1]::run_compiler::{closure#1}>::{closure#0}, core[d525c930f060fa4e]::result::Result<(), rustc_errors[a92f92f3abe4e548]::ErrorGuaranteed>>::{closure#0}, core[d525c930f060fa4e]::result::Result<(), rustc_errors[a92f92f3abe4e548]::ErrorGuaranteed>>::{closure#1} as core[d525c930f060fa4e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  25:     0x7f3a43cdf363 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc33c8b6114373b1d
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/alloc/src/boxed.rs:1940:9
  26:     0x7f3a43cdf363 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h477ba7c62d8daaed
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/alloc/src/boxed.rs:1940:9
  27:     0x7f3a43cdf363 - std::sys::unix::thread::Thread::new::thread_start::h7a4a94e6bf66c5d5
                               at /rustc/3f83906b30798bf61513fa340524cebf6676f9db/library/std/src/sys/unix/thread.rs:108:17
  28:     0x7f3a43a33b43 - <unknown>
  29:     0x7f3a43ac5a00 - <unknown>
  30:                0x0 - <unknown>

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.66.0-nightly (3f83906b3 2022-09-24) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
thread panicked while panicking. aborting.
error: could not compile `ice`

Caused by:
  process didn't exit successfully: `rustc --crate-name ice --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=2cc8a57eb73b0fe5 -C extra-filename=-2cc8a57eb73b0fe5 --out-dir /home/ubuntu/dev/ice/target/debug/deps -C incremental=/home/ubuntu/dev/ice/target/debug/incremental -L dependency=/home/ubuntu/dev/ice/target/debug/deps` (signal: 6, SIGABRT: process abort signal)
```

</p>
</details>