Repository: rust
Issue: `unexpected inference var` in `type_check/relate_tys.rs`
Labels: I-ICE,T-compiler,C-bug

<!--
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

```Rust
trait UnwrapItemsExt<'a, > {
    type Iter;=
}

struct MyStruct<const C: usize> {}
trait MyTrait<'a, const C: usize> {}

impl<'a, const C: usize> MyTrait<'a, C> for MyStruct<C> {
}

impl<'a, I, const C: usize> UnwrapItemsExt<'a, C> for I {
    type Iter = impl MyTrait<'a, C>;
    fn unwrap_items(self) -> Self::Iter {
        MyStruct::<C> {}
    }
}

fn main() {} 
```


### 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.79.0-nightly (385fa9d84 2024-04-04)
binary: rustc
commit-hash: 385fa9d845dd326c6bbfd58c22244215e431948a
commit-date: 2024-04-04
host: x86_64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.2
```

### Error output

```
error: non-item in item list
 --> ./D6BD4FB55462A1C16D63A187D670720C36D17D621F27BB3730F935512411FC53.rs:2:15
  |
1 | trait UnwrapItemsExt<'a, > {
  |                            - item list starts here
2 |     type Iter;=
  |               ^ non-item starts here
3 | }
  | - item list ends here

error[E0407]: method `unwrap_items` is not a member of trait `UnwrapItemsExt`
  --> ./D6BD4FB55462A1C16D63A187D670720C36D17D621F27BB3730F935512411FC53.rs:13:5
   |
13 | /     fn unwrap_items(self) -> Self::Iter {
14 | |         MyStruct::<C> {}
15 | |     }
   | |_____^ not a member of trait `UnwrapItemsExt`

error[E0658]: `impl Trait` in associated types is unstable
  --> ./D6BD4FB55462A1C16D63A187D670720C36D17D621F27BB3730F935512411FC53.rs:12:17
   |
12 |     type Iter = impl MyTrait<'a, C>;
   |                 ^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
   = help: add `#![feature(impl_trait_in_assoc_type)]` to the crate attributes to enable
   = note: this compiler was built on 2024-04-04; consider upgrading it if it is out of date

error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
  --> ./D6BD4FB55462A1C16D63A187D670720C36D17D621F27BB3730F935512411FC53.rs:11:29
   |
11 | impl<'a, I, const C: usize> UnwrapItemsExt<'a, C> for I {
   |                             ^^^^^^^^^^^^^^ expected 0 generic arguments
   |
note: trait defined here, with 0 generic parameters
  --> ./D6BD4FB55462A1C16D63A187D670720C36D17D621F27BB3730F935512411FC53.rs:1:7
   |
1  | trait UnwrapItemsExt<'a, > {
   |       ^^^^^^^^^^^^^^

error[E0207]: the const parameter `C` is not constrained by the impl trait, self type, or predicates
  --> ./D6BD4FB55462A1C16D63A187D670720C36D17D621F27BB3730F935512411FC53.rs:11:13
   |
11 | impl<'a, I, const C: usize> UnwrapItemsExt<'a, C> for I {
   |             ^^^^^^^^^^^^^^ unconstrained const parameter
   |
   = note: expressions using a const parameter must map each value to a distinct output value
   = note: proving the result of expressions other than the parameter are unique is not supported
```

<!--
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 compiler/rustc_borrowck/src/type_check/relate_tys.rs:441:9:
unexpected inference var ?0c: usize
stack backtrace:
   0:        0x103492797 - std::backtrace::Backtrace::create::h72d3f6df5a38e04e
   1:        0x1034926e5 - std::backtrace::Backtrace::force_capture::hfb9db3afdd7ed5a0
   2:        0x10c041cfb - std[be7050f24520aea4]::panicking::update_hook::<alloc[2a9bcbeb98b329c5]::boxed::Box<rustc_driver_impl[8bfb916414656838]::install_ice_hook::{closure#0}>>::{closure#0}
   3:        0x1034ac564 - std::panicking::rust_panic_with_hook::hd67e9f54f7f40054
   4:        0x1034abea4 - std::panicking::begin_panic_handler::{{closure}}::h8d3afd8e6d4ebb5c
   5:        0x1034a9379 - std::sys_common::backtrace::__rust_end_short_backtrace::h18e72b50cfea1b84
   6:        0x1034abbd6 - _rust_begin_unwind
   7:        0x103511355 - core::panicking::panic_fmt::hdd6020c145d16e40
   8:        0x10bb697b4 - <rustc_borrowck[b118bb05d7b0041d]::type_check::relate_tys::NllTypeRelating as rustc_middle[1ad5f3b6432680d2]::ty::relate::TypeRelation>::consts
   9:        0x10bbad2fc - <rustc_borrowck[b118bb05d7b0041d]::type_check::relate_tys::NllTypeRelating as rustc_middle[1ad5f3b6432680d2]::ty::relate::TypeRelation>::relate_with_variance::<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg>
  10:        0x10ba39b3d - <core[95a55440902af925]::iter::adapters::GenericShunt<core[95a55440902af925]::iter::adapters::map::Map<core[95a55440902af925]::iter::adapters::enumerate::Enumerate<core[95a55440902af925]::iter::adapters::zip::Zip<core[95a55440902af925]::iter::adapters::copied::Copied<core[95a55440902af925]::slice::iter::Iter<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg>>, core[95a55440902af925]::iter::adapters::copied::Copied<core[95a55440902af925]::slice::iter::Iter<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg>>>>, rustc_middle[1ad5f3b6432680d2]::ty::relate::relate_args_with_variances<rustc_borrowck[b118bb05d7b0041d]::type_check::relate_tys::NllTypeRelating>::{closure#0}>, core[95a55440902af925]::result::Result<core[95a55440902af925]::convert::Infallible, rustc_middle[1ad5f3b6432680d2]::ty::error::TypeError>> as core[95a55440902af925]::iter::traits::iterator::Iterator>::try_fold::<(), core[95a55440902af925]::iter::traits::iterator::Iterator::try_for_each::call<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg, core[95a55440902af925]::ops::control_flow::ControlFlow<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg>, core[95a55440902af925]::ops::control_flow::ControlFlow<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg>::Break>::{closure#0}, core[95a55440902af925]::ops::control_flow::ControlFlow<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg>>
  11:        0x10ba52d29 - <core[95a55440902af925]::result::Result<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg, rustc_middle[1ad5f3b6432680d2]::ty::error::TypeError> as rustc_type_ir[39b748d160e12b68]::interner::CollectAndApply<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg, &rustc_middle[1ad5f3b6432680d2]::ty::list::List<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg>>>::collect_and_apply::<core[95a55440902af925]::iter::adapters::map::Map<core[95a55440902af925]::iter::adapters::enumerate::Enumerate<core[95a55440902af925]::iter::adapters::zip::Zip<core[95a55440902af925]::iter::adapters::copied::Copied<core[95a55440902af925]::slice::iter::Iter<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg>>, core[95a55440902af925]::iter::adapters::copied::Copied<core[95a55440902af925]::slice::iter::Iter<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg>>>>, rustc_middle[1ad5f3b6432680d2]::ty::relate::relate_args_with_variances<rustc_borrowck[b118bb05d7b0041d]::type_check::relate_tys::NllTypeRelating>::{closure#0}>, <rustc_middle[1ad5f3b6432680d2]::ty::context::TyCtxt>::mk_args_from_iter<core[95a55440902af925]::iter::adapters::map::Map<core[95a55440902af925]::iter::adapters::enumerate::Enumerate<core[95a55440902af925]::iter::adapters::zip::Zip<core[95a55440902af925]::iter::adapters::copied::Copied<core[95a55440902af925]::slice::iter::Iter<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg>>, core[95a55440902af925]::iter::adapters::copied::Copied<core[95a55440902af925]::slice::iter::Iter<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg>>>>, rustc_middle[1ad5f3b6432680d2]::ty::relate::relate_args_with_variances<rustc_borrowck[b118bb05d7b0041d]::type_check::relate_tys::NllTypeRelating>::{closure#0}>, core[95a55440902af925]::result::Result<rustc_middle[1ad5f3b6432680d2]::ty::generic_args::GenericArg, rustc_middle[1ad5f3b6432680d2]::ty::error::TypeError>>::{closure#0}>
  12:        0x10ba3b842 - <rustc_middle[1ad5f3b6432680d2]::ty::sty::AliasTy as rustc_middle[1ad5f3b6432680d2]::ty::relate::Relate>::relate::<rustc_borrowck[b118bb05d7b0041d]::type_check::relate_tys::NllTypeRelating>
  13:        0x10b9b7394 - <rustc_infer[243809f999046ed9]::infer::InferCtxt>::super_combine_tys::<rustc_borrowck[b118bb05d7b0041d]::type_check::relate_tys::NllTypeRelating>
  14:        0x10bbad962 - <rustc_borrowck[b118bb05d7b0041d]::type_check::relate_tys::NllTypeRelating as rustc_middle[1ad5f3b6432680d2]::ty::relate::TypeRelation>::tys
  15:        0x10bbac7c4 - <rustc_borrowck[b118bb05d7b0041d]::type_check::TypeChecker>::relate_types
  16:        0x10bbac532 - <rustc_borrowck[b118bb05d7b0041d]::type_check::TypeChecker>::equate_normalized_input_or_output
  17:        0x10bb6deb1 - rustc_borrowck[b118bb05d7b0041d]::type_check::type_check
  18:        0x10bb3f190 - rustc_borrowck[b118bb05d7b0041d]::nll::compute_regions
  19:        0x10bbbc428 - rustc_borrowck[b118bb05d7b0041d]::do_mir_borrowck
  20:        0x10bb81df2 - rustc_borrowck[b118bb05d7b0041d]::mir_borrowck
  21:        0x10d46963a - rustc_query_impl[90888abca995a36a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[90888abca995a36a]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 8usize]>>
  22:        0x10d2eeccc - rustc_query_system[86526c3e26299dee]::query::plumbing::try_execute_query::<rustc_query_impl[90888abca995a36a]::DynamicConfig<rustc_query_system[86526c3e26299dee]::query::caches::VecCache<rustc_hir[36aeddbba5c0fbdc]::hir_id::OwnerId, rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[90888abca995a36a]::plumbing::QueryCtxt, false>
  23:        0x10d49198b - rustc_query_impl[90888abca995a36a]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  24:        0x10c24cf78 - rustc_middle[1ad5f3b6432680d2]::query::plumbing::query_get_at::<rustc_query_system[86526c3e26299dee]::query::caches::VecCache<rustc_hir[36aeddbba5c0fbdc]::hir_id::OwnerId, rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 8usize]>>>
  25:        0x10c3be570 - <rustc_hir_analysis[9a5a8480ab2c754]::collect::type_of::opaque::TaitConstraintLocator>::check
  26:        0x10c358e4a - rustc_hir_analysis[9a5a8480ab2c754]::collect::type_of::type_of_opaque
  27:        0x10d469eaa - rustc_query_impl[90888abca995a36a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[90888abca995a36a]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 8usize]>>
  28:        0x10d24bb93 - rustc_query_system[86526c3e26299dee]::query::plumbing::try_execute_query::<rustc_query_impl[90888abca995a36a]::DynamicConfig<rustc_query_system[86526c3e26299dee]::query::caches::DefIdCache<rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[90888abca995a36a]::plumbing::QueryCtxt, false>
  29:        0x10d476ca9 - rustc_query_impl[90888abca995a36a]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
  30:        0x10c24c52e - rustc_middle[1ad5f3b6432680d2]::query::plumbing::query_get_at::<rustc_query_system[86526c3e26299dee]::query::caches::DefIdCache<rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 8usize]>>>
  31:        0x10c357bed - rustc_hir_analysis[9a5a8480ab2c754]::collect::type_of::type_of
  32:        0x10d46da66 - rustc_query_impl[90888abca995a36a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[90888abca995a36a]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 8usize]>>
  33:        0x10d24bb93 - rustc_query_system[86526c3e26299dee]::query::plumbing::try_execute_query::<rustc_query_impl[90888abca995a36a]::DynamicConfig<rustc_query_system[86526c3e26299dee]::query::caches::DefIdCache<rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[90888abca995a36a]::plumbing::QueryCtxt, false>
  34:        0x10d4768f9 - rustc_query_impl[90888abca995a36a]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  35:        0x10c24c52e - rustc_middle[1ad5f3b6432680d2]::query::plumbing::query_get_at::<rustc_query_system[86526c3e26299dee]::query::caches::DefIdCache<rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 8usize]>>>
  36:        0x10c2c6352 - rustc_hir_analysis[9a5a8480ab2c754]::check::check::check_item_type
  37:        0x10c2fdca9 - rustc_hir_analysis[9a5a8480ab2c754]::check::wfcheck::check_well_formed
  38:        0x10d46ad6a - rustc_query_impl[90888abca995a36a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[90888abca995a36a]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 1usize]>>
  39:        0x10d2ec8fc - rustc_query_system[86526c3e26299dee]::query::plumbing::try_execute_query::<rustc_query_impl[90888abca995a36a]::DynamicConfig<rustc_query_system[86526c3e26299dee]::query::caches::VecCache<rustc_hir[36aeddbba5c0fbdc]::hir_id::OwnerId, rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[90888abca995a36a]::plumbing::QueryCtxt, false>
  40:        0x10d4b17e0 - rustc_query_impl[90888abca995a36a]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  41:        0x10c24d527 - rustc_middle[1ad5f3b6432680d2]::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system[86526c3e26299dee]::query::caches::VecCache<rustc_hir[36aeddbba5c0fbdc]::hir_id::OwnerId, rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 1usize]>>, ()>
  42:        0x10c30b9b1 - rustc_hir_analysis[9a5a8480ab2c754]::check::wfcheck::check_mod_type_wf
  43:        0x10d46ad5a - rustc_query_impl[90888abca995a36a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[90888abca995a36a]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 1usize]>>
  44:        0x10d2a2b91 - rustc_query_system[86526c3e26299dee]::query::plumbing::try_execute_query::<rustc_query_impl[90888abca995a36a]::DynamicConfig<rustc_query_system[86526c3e26299dee]::query::caches::DefaultCache<rustc_span[3abddbc5b7091f5a]::def_id::LocalModDefId, rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[90888abca995a36a]::plumbing::QueryCtxt, false>
  45:        0x10d48fc80 - rustc_query_impl[90888abca995a36a]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  46:        0x10c383a6c - rustc_hir_analysis[9a5a8480ab2c754]::check_crate
  47:        0x10c7eb1e0 - rustc_interface[230cab390baedc2]::passes::analysis
  48:        0x10d46da7a - rustc_query_impl[90888abca995a36a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[90888abca995a36a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 1usize]>>
  49:        0x10d256efe - rustc_query_system[86526c3e26299dee]::query::plumbing::try_execute_query::<rustc_query_impl[90888abca995a36a]::DynamicConfig<rustc_query_system[86526c3e26299dee]::query::caches::SingleCache<rustc_middle[1ad5f3b6432680d2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[90888abca995a36a]::plumbing::QueryCtxt, false>
  50:        0x10d477e47 - rustc_query_impl[90888abca995a36a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  51:        0x10bfed5a7 - <rustc_interface[230cab390baedc2]::queries::QueryResult<&rustc_middle[1ad5f3b6432680d2]::ty::context::GlobalCtxt>>::enter::<core[95a55440902af925]::result::Result<(), rustc_span[3abddbc5b7091f5a]::ErrorGuaranteed>, rustc_driver_impl[8bfb916414656838]::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  52:        0x10c0401af - rustc_interface[230cab390baedc2]::interface::run_compiler::<core[95a55440902af925]::result::Result<(), rustc_span[3abddbc5b7091f5a]::ErrorGuaranteed>, rustc_driver_impl[8bfb916414656838]::run_compiler::{closure#0}>::{closure#0}
  53:        0x10c0375ad - std[be7050f24520aea4]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[230cab390baedc2]::util::run_in_thread_with_globals<rustc_interface[230cab390baedc2]::util::run_in_thread_pool_with_globals<rustc_interface[230cab390baedc2]::interface::run_compiler<core[95a55440902af925]::result::Result<(), rustc_span[3abddbc5b7091f5a]::ErrorGuaranteed>, rustc_driver_impl[8bfb916414656838]::run_compiler::{closure#0}>::{closure#0}, core[95a55440902af925]::result::Result<(), rustc_span[3abddbc5b7091f5a]::ErrorGuaranteed>>::{closure#0}, core[95a55440902af925]::result::Result<(), rustc_span[3abddbc5b7091f5a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[95a55440902af925]::result::Result<(), rustc_span[3abddbc5b7091f5a]::ErrorGuaranteed>>
  54:        0x10c04998f - <<std[be7050f24520aea4]::thread::Builder>::spawn_unchecked_<rustc_interface[230cab390baedc2]::util::run_in_thread_with_globals<rustc_interface[230cab390baedc2]::util::run_in_thread_pool_with_globals<rustc_interface[230cab390baedc2]::interface::run_compiler<core[95a55440902af925]::result::Result<(), rustc_span[3abddbc5b7091f5a]::ErrorGuaranteed>, rustc_driver_impl[8bfb916414656838]::run_compiler::{closure#0}>::{closure#0}, core[95a55440902af925]::result::Result<(), rustc_span[3abddbc5b7091f5a]::ErrorGuaranteed>>::{closure#0}, core[95a55440902af925]::result::Result<(), rustc_span[3abddbc5b7091f5a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[95a55440902af925]::result::Result<(), rustc_span[3abddbc5b7091f5a]::ErrorGuaranteed>>::{closure#1} as core[95a55440902af925]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  55:        0x1034b574b - std::sys::pal::unix::thread::Thread::new::thread_start::he5f939c93f920ed5
  56:     0x7ff818270202 - __pthread_start


rustc version: 1.79.0-nightly (385fa9d84 2024-04-04)
platform: x86_64-apple-darwin

query stack during panic:
#0 [mir_borrowck] borrow-checking `<impl at ./D6BD4FB55462A1C16D63A187D670720C36D17D621F27BB3730F935512411FC53.rs:11:1: 11:56>::unwrap_items`
#1 [type_of_opaque] computing type of opaque `<impl at ./D6BD4FB55462A1C16D63A187D670720C36D17D621F27BB3730F935512411FC53.rs:11:1: 11:56>::Iter::{opaque#0}`
#2 [type_of] computing type of `<impl at ./D6BD4FB55462A1C16D63A187D670720C36D17D621F27BB3730F935512411FC53.rs:11:1: 11:56>::Iter::{opaque#0}`
#3 [check_well_formed] checking that `<impl at ./D6BD4FB55462A1C16D63A187D670720C36D17D621F27BB3730F935512411FC53.rs:11:1: 11:56>::Iter::{opaque#0}` is well-formed
#4 [check_mod_type_wf] checking that types are well-formed in top-level module
#5 [analysis] running analysis passes on this crate
end of query stack
```

</p>
</details>