Repository: rust
Issue: ICE: `range end index 2 out of range for slice of length 1`
Labels: A-pretty,I-ICE,T-compiler,C-bug,F-unboxed_closures,S-has-mcve,S-bug-has-test,S-has-bisection

<!--
[31mICE[0m: Rustc ./a.rs '' 'thread 'rustc' panicked at compiler/rustc_middle/src/ty/generics.rs:311:14: 'range end index 2 out of range for slice of length 1'', 'thread 'rustc' panicked at compiler/rustc_middle/src/ty/generics.rs:311:14: 'range end index 2 out of range for slice of length 1''
File: /tmp/im/a.rs
-->

auto-reduced (treereduce-rust):
````rust
pub trait Foo2 {
    fn boxed<'a: 'a>() -> impl Sized + FnOnce<()>;
}

impl Foo2 for () {}

````

original:
````rust
pub trait Foo2 {
    fn boxed<'a: 'a>(&'a mut self) -> impl Sized + FnOnce<()>;
}

impl Foo2 for () {
    fn bar<'a: Add<S<M>>>(&'a mut self) -> impl Sized + 'a {}
}

````

Version information
````
rustc 1.85.0-nightly (7e565cce6 2024-11-28)
binary: rustc
commit-hash: 7e565cce6a03340edb4b9f56228cf5e480e24806
commit-date: 2024-11-28
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.4

````

Possibly related line of code:
https://github.com/rust-lang/rust/blob/7e565cce6a03340edb4b9f56228cf5e480e24806/compiler/rustc_middle/src/ty/generics.rs#L305-L317

Command:
`/home/matthias/.rustup/toolchains/master/bin/rustc `

<details><summary><strong>Program output</strong></summary>
<p>

```
error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.9uBYr2RCUK08/rustc_testrunner_tmpdir_reporting.WADMNevz7sTe/mvce.rs:5:20
  |
5 | impl Foo2 for () {}
  |                    ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.9uBYr2RCUK08/rustc_testrunner_tmpdir_reporting.WADMNevz7sTe/mvce.rs`

error[E0658]: the precise format of `Fn`-family traits' type parameters is subject to change
 --> /tmp/icemaker_global_tempdir.9uBYr2RCUK08/rustc_testrunner_tmpdir_reporting.WADMNevz7sTe/mvce.rs:2:40
  |
2 |     fn boxed<'a: 'a>() -> impl Sized + FnOnce<()>;
  |                                        ^^^^^^^^^^ help: use parenthetical notation instead: `FnOnce() -> ()`
  |
  = note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information
  = help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
  = note: this compiler was built on 2024-11-28; consider upgrading it if it is out of date

thread 'rustc' panicked at compiler/rustc_middle/src/ty/generics.rs:311:14:
range end index 2 out of range for slice of length 1
stack backtrace:
   0:     0x73c32e66098a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h7f35c99327b4f726
   1:     0x73c32ee1c43c - core::fmt::write::h5e97d25008730389
   2:     0x73c33028e1d1 - std::io::Write::write_fmt::h1ae9ed15ab76812c
   3:     0x73c32e6607e2 - std::sys::backtrace::BacktraceLock::print::ha255d6c77b9d7dcc
   4:     0x73c32e662cba - std::panicking::default_hook::{{closure}}::hf875838f93ccbb14
   5:     0x73c32e662b20 - std::panicking::default_hook::hd7f37029cbcc8aec
   6:     0x73c32d72a895 - std[2251e1dccffdccbc]::panicking::update_hook::<alloc[2789366f424f3027]::boxed::Box<rustc_driver_impl[5761ece06b1326ab]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x73c32e663398 - std::panicking::rust_panic_with_hook::hb2d4571765667af8
   8:     0x73c32e66316a - std::panicking::begin_panic_handler::{{closure}}::h88452831bc745907
   9:     0x73c32e660e39 - std::sys::backtrace::__rust_end_short_backtrace::h25d51a3907f0597d
  10:     0x73c32e662e2c - rust_begin_unwind
  11:     0x73c32b0f29b0 - core::panicking::panic_fmt::hadb465d335389640
  12:     0x73c32d128f57 - core::slice::index::slice_end_index_len_fail::do_panic::runtime::h62f89e537db414d8
  13:     0x73c32c85cd9a - core::slice::index::slice_end_index_len_fail::h3f0970a4378a8a5f
  14:     0x73c330b0277e - <rustc_middle[dedf341fffa9562c]::ty::generics::Generics>::own_args_no_defaults.cold
  15:     0x73c32dd8f1c3 - <rustc_middle[dedf341fffa9562c]::ty::print::pretty::FmtPrinter as rustc_middle[dedf341fffa9562c]::ty::print::pretty::PrettyPrinter>::pretty_print_opaque_impl_type
  16:     0x73c32fea9f62 - <rustc_middle[dedf341fffa9562c]::ty::print::pretty::FmtPrinter as rustc_middle[dedf341fffa9562c]::ty::print::pretty::PrettyPrinter>::pretty_print_type
  17:     0x73c32fea7d6e - <rustc_middle[dedf341fffa9562c]::ty::Ty as core[1880415d78dd9be6]::fmt::Display>::fmt
  18:     0x73c32ee1c43c - core::fmt::write::h5e97d25008730389
  19:     0x73c32ee1c2a0 - alloc::fmt::format::format_inner::h8741e8344250b15d
  20:     0x73c3300d6604 - rustc_hir_analysis[843c6fea6ca9eb60]::check::check::check_impl_items_against_trait
  21:     0x73c33001f9d1 - rustc_hir_analysis[843c6fea6ca9eb60]::check::check::check_item_type
  22:     0x73c32bd8a764 - rustc_hir_analysis[843c6fea6ca9eb60]::check::wfcheck::check_well_formed
  23:     0x73c32f3324a7 - rustc_query_impl[2e40c9ff1be86589]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2e40c9ff1be86589]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dedf341fffa9562c]::query::erase::Erased<[u8; 1usize]>>
  24:     0x73c32f332780 - rustc_query_system[eb8ffdfd9c7325e5]::query::plumbing::try_execute_query::<rustc_query_impl[2e40c9ff1be86589]::DynamicConfig<rustc_data_structures[f36924e63485e28e]::vec_cache::VecCache<rustc_span[47c6aef7bb9494a9]::def_id::LocalDefId, rustc_middle[dedf341fffa9562c]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[eb8ffdfd9c7325e5]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[2e40c9ff1be86589]::plumbing::QueryCtxt, false>
  25:     0x73c32f332486 - rustc_query_impl[2e40c9ff1be86589]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  26:     0x73c32f33322c - rustc_hir_analysis[843c6fea6ca9eb60]::check::wfcheck::check_mod_type_wf
  27:     0x73c32f33304b - rustc_query_impl[2e40c9ff1be86589]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2e40c9ff1be86589]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dedf341fffa9562c]::query::erase::Erased<[u8; 1usize]>>
  28:     0x73c32f96ebbd - rustc_query_system[eb8ffdfd9c7325e5]::query::plumbing::try_execute_query::<rustc_query_impl[2e40c9ff1be86589]::DynamicConfig<rustc_query_system[eb8ffdfd9c7325e5]::query::caches::DefaultCache<rustc_span[47c6aef7bb9494a9]::def_id::LocalModDefId, rustc_middle[dedf341fffa9562c]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[2e40c9ff1be86589]::plumbing::QueryCtxt, false>
  29:     0x73c32f96e958 - rustc_query_impl[2e40c9ff1be86589]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  30:     0x73c32f0ce81e - rustc_hir_analysis[843c6fea6ca9eb60]::check_crate
  31:     0x73c32f7bf68c - rustc_interface[790a5929a84e5ed3]::passes::run_required_analyses
  32:     0x73c32f7b399e - rustc_interface[790a5929a84e5ed3]::passes::analysis
  33:     0x73c32f7b396f - rustc_query_impl[2e40c9ff1be86589]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2e40c9ff1be86589]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dedf341fffa9562c]::query::erase::Erased<[u8; 1usize]>>
  34:     0x73c32fe2966e - rustc_query_system[eb8ffdfd9c7325e5]::query::plumbing::try_execute_query::<rustc_query_impl[2e40c9ff1be86589]::DynamicConfig<rustc_query_system[eb8ffdfd9c7325e5]::query::caches::SingleCache<rustc_middle[dedf341fffa9562c]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[2e40c9ff1be86589]::plumbing::QueryCtxt, false>
  35:     0x73c32fe2934e - rustc_query_impl[2e40c9ff1be86589]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  36:     0x73c32fdf1155 - rustc_interface[790a5929a84e5ed3]::interface::run_compiler::<core[1880415d78dd9be6]::result::Result<(), rustc_span[47c6aef7bb9494a9]::ErrorGuaranteed>, rustc_driver_impl[5761ece06b1326ab]::run_compiler::{closure#0}>::{closure#1}
  37:     0x73c32fcecd54 - std[2251e1dccffdccbc]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[790a5929a84e5ed3]::util::run_in_thread_with_globals<rustc_interface[790a5929a84e5ed3]::util::run_in_thread_pool_with_globals<rustc_interface[790a5929a84e5ed3]::interface::run_compiler<core[1880415d78dd9be6]::result::Result<(), rustc_span[47c6aef7bb9494a9]::ErrorGuaranteed>, rustc_driver_impl[5761ece06b1326ab]::run_compiler::{closure#0}>::{closure#1}, core[1880415d78dd9be6]::result::Result<(), rustc_span[47c6aef7bb9494a9]::ErrorGuaranteed>>::{closure#0}, core[1880415d78dd9be6]::result::Result<(), rustc_span[47c6aef7bb9494a9]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1880415d78dd9be6]::result::Result<(), rustc_span[47c6aef7bb9494a9]::ErrorGuaranteed>>
  38:     0x73c32fceca7d - <<std[2251e1dccffdccbc]::thread::Builder>::spawn_unchecked_<rustc_interface[790a5929a84e5ed3]::util::run_in_thread_with_globals<rustc_interface[790a5929a84e5ed3]::util::run_in_thread_pool_with_globals<rustc_interface[790a5929a84e5ed3]::interface::run_compiler<core[1880415d78dd9be6]::result::Result<(), rustc_span[47c6aef7bb9494a9]::ErrorGuaranteed>, rustc_driver_impl[5761ece06b1326ab]::run_compiler::{closure#0}>::{closure#1}, core[1880415d78dd9be6]::result::Result<(), rustc_span[47c6aef7bb9494a9]::ErrorGuaranteed>>::{closure#0}, core[1880415d78dd9be6]::result::Result<(), rustc_span[47c6aef7bb9494a9]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1880415d78dd9be6]::result::Result<(), rustc_span[47c6aef7bb9494a9]::ErrorGuaranteed>>::{closure#1} as core[1880415d78dd9be6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x73c32fcec239 - std::sys::pal::unix::thread::Thread::new::thread_start::h4f639267331689fa
  40:     0x73c3315b039d - <unknown>
  41:     0x73c33163549c - <unknown>
  42:                0x0 - <unknown>

error: 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: please make sure that you have updated to the latest nightly

note: rustc 1.85.0-nightly (7e565cce6 2024-11-28) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.9uBYr2RCUK08/rustc_testrunner_tmpdir_reporting.WADMNevz7sTe/mvce.rs:5:1: 5:17>` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
end of query stack
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0601, E0658.
For more information about an error, try `rustc --explain E0601`.

```

</p>
</details>

<!--
query stack:
#0 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.9uBYr2RCUK08/rustc_testrunner_tmpdir_reporting.WADMNevz7sTe/mvce.rs:5:1: 5:17>` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module

-->