Skip to content

ICE: range end index 2 out of range for slice of length 1 #133597

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
matthiaskrgr opened this issue Nov 28, 2024 · 4 comments · Fixed by #137458
Closed

ICE: range end index 2 out of range for slice of length 1 #133597

matthiaskrgr opened this issue Nov 28, 2024 · 4 comments · Fixed by #137458
Assignees
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. F-unboxed_closures `#![feature(unboxed_closures)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-bisection Status: A bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

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

impl Foo2 for () {}

original:

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:

param.default_value(tcx).is_some_and(|default| {
default.instantiate(tcx, args) == args[param.index as usize]
})
})
.count();
&args[own_params]
}
/// Returns the args corresponding to the generic parameters of this item, excluding `Self`.
///
/// **This should only be used for diagnostics purposes.**
pub fn own_args(

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

Program output

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`.

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 28, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 28, 2024
@matthiaskrgr
Copy link
Member Author

mvce

trait a{fn b->impl FnOnce<()>} impl a for ();

@jieyouxu jieyouxu added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Nov 29, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Nov 29, 2024

The MCVE regressed (errors -> ICE) on

********************************************************************************
Regression in nightly-2024-11-25
********************************************************************************

fetching https://static.rust-lang.org/dist/2024-11-24/channel-rust-nightly-git-commit-hash.txt
ERROR: Tarball not found at https://static.rust-lang.org/dist/2024-11-24/channel-rust-nightly-git-commit-hash.txt

@jieyouxu
Copy link
Member

jieyouxu commented Nov 29, 2024

Bisected to #132911 via manual git revert + testing the MCVE. Not really helpful because the pretty printer logic had some very... interesting things going on. Anyway, cc @compiler-errors but yeah.

@jieyouxu jieyouxu added A-pretty Area: Pretty printing (including `-Z unpretty`) S-has-bisection Status: A bisection has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 29, 2024
@fmease fmease added the F-unboxed_closures `#![feature(unboxed_closures)]` label Nov 29, 2024
@fmease
Copy link
Member

fmease commented Nov 29, 2024

Nice, GH finally notifies people if a subscribed PR gets mentioned :)

Conceptually simpler MCVE:

fn f() -> impl FnOnce<()> { || () }
fn main() { () = f(); }

No RPITITs necessary. FnOnce can be substituted with Fn and FnMut to the same effect.

So odd that we don't have a test for this super simple snippet :O

@fmease fmease self-assigned this Dec 4, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Dec 14, 2024
@compiler-errors compiler-errors marked this as a duplicate of #137456 Feb 23, 2025
@bors bors closed this as completed in d415200 Feb 23, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 23, 2025
Rollup merge of rust-lang#137458 - compiler-errors:render-fn, r=fmease

Fix missing self subst when rendering `impl Fn*<T>` with no output type

r? `@fmease` or reassign

Fixes rust-lang#133597
cc rust-lang#137456
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. F-unboxed_closures `#![feature(unboxed_closures)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-bisection Status: A bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants