Repository: rust
Issue: ice: `TyKind::Error constructed but no error reported`
Labels: I-ICE,A-trait-system,T-compiler,A-impl-trait,C-bug,glacier,S-bug-has-test,T-types,fixed-by-next-solver

<!--
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
pub fn compose(
    f1: impl FnOnce(f64) -> f64 + Clone,
    f2: impl FnOnce(f64) -> f64 + Clone,
) -> impl FnOnce(f64) -> f64 + Clone {
    move |x| f1(f2(x))
}

fn repeat_helper(
    f: impl FnOnce(f64) -> f64 + Clone,
    res: impl FnOnce(f64) -> f64 + Clone,
    times: usize,
) -> impl FnOnce(f64) -> f64 + Clone {
    return res;
    repeat_helper(f.clone(), compose(f, res), times - 1)
}

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.72.0-nightly (d59363ad0 2023-06-01)
binary: rustc
commit-hash: d59363ad0b6391b7fc5bbb02c9ccf9300eef3753
commit-date: 2023-06-01
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.4
```

### Error output

```
warning: unreachable expression
  --> treereduce.out:14:5
   |
13 |     return res;
   |     ---------- any code following this expression is unreachable
14 |     repeat_helper(f.clone(), compose(f, res), times - 1)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable expression
   |
   = note: `#[warn(unreachable_code)]` on by default

warning: unused variable: `f`
 --> treereduce.out:9:5
  |
9 |     f: impl FnOnce(f64) -> f64 + Clone,
  |     ^ help: if this is intentional, prefix it with an underscore: `_f`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `times`
  --> treereduce.out:11:5
   |
11 |     times: usize,
   |     ^^^^^ help: if this is intentional, prefix it with an underscore: `_times`

warning: function `repeat_helper` is never used
 --> treereduce.out:8:4
  |
8 | fn repeat_helper(
  |    ^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default
```

<!--
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>

```
error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_middle/src/ty/opaque_types.rs:189:41
             0: <rustc_errors::HandlerInner>::emit_diagnostic
             1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
             2: <rustc_middle::ty::context::TyCtxt>::ty_error_misc
             3: <rustc_middle::ty::opaque_types::ReverseMapper as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_ty
             4: <rustc_middle::ty::OpaqueHiddenType>::remap_generic_params_to_declaration_params
             5: rustc_hir_analysis::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit
             6: rustc_hir_analysis::collect::type_of::type_of
             7: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
             8: <rustc_query_impl::query_impl::type_of::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId)>>::call_once
             9: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            10: rustc_query_impl::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
            11: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
            12: rustc_hir_analysis::check::check::check_mod_item_types
            13: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_mod_item_types::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
            14: <rustc_query_impl::query_impl::check_mod_item_types::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
            15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            16: rustc_query_impl::query_impl::check_mod_item_types::get_query_non_incr::__rust_end_short_backtrace
            17: <rustc_middle::hir::map::Map>::for_each_module::<rustc_hir_analysis::check_crate::{closure#6}::{closure#0}>
            18: <rustc_session::session::Session>::time::<(), rustc_hir_analysis::check_crate::{closure#6}>
            19: rustc_hir_analysis::check_crate
            20: rustc_interface::passes::analysis
            21: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
            22: <rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
            23: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            24: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
            25: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            26: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
            27: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            28: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            29: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            30: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/d59363ad0b6391b7fc5bbb02c9ccf9300eef3753/library/alloc/src/boxed.rs:1985:9
            31: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/d59363ad0b6391b7fc5bbb02c9ccf9300eef3753/library/alloc/src/boxed.rs:1985:9
            32: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/d59363ad0b6391b7fc5bbb02c9ccf9300eef3753/library/std/src/sys/unix/thread.rs:108:17
            33: <unknown>
            34: <unknown>


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.72.0-nightly (d59363ad0 2023-06-01) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
error: aborting due to 2 previous errors; 4 warnings emitted
```

</p>
</details>