Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ICE: generic_const_exprs "range end index 2 out of range for slice of length 1" #105257

Closed
matthiaskrgr opened this issue Dec 4, 2022 · 1 comment · Fixed by #105410
Closed
Assignees
Labels
C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

rustc "-Zcrate-attr=feature(generic_const_exprs)"

trait Trait<const N: Trait = bar> {
    fn fnc<const N: Trait = u32>(&self) -> Trait {
        bar
    }
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.67.0-nightly (234151769 2022-12-03)
binary: rustc
commit-hash: 23415176968e81e0aac92d0218612a89c4e68a82
commit-date: 2022-12-03
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Error output

error[E0403]: the name `N` is already used for a generic parameter in this item's generic parameters
 --> 152f764c6622dfef067008fe2bb5329872ae96ed.rs:2:18
  |
1 | trait Trait<const N: Trait = bar> {
  |                   - first use of `N`
2 |     fn fnc<const N: Trait = u32>(&self) -> Trait {
  |                  ^ already used

error[E0425]: cannot find value `bar` in this scope
 --> 152f764c6622dfef067008fe2bb5329872ae96ed.rs:1:30
  |
1 | trait Trait<const N: Trait = bar> {
  |                              ^^^ not found in this scope

error[E0423]: expected value, found builtin type `u32`
 --> 152f764c6622dfef067008fe2bb5329872ae96ed.rs:2:29
  |
2 |     fn fnc<const N: Trait = u32>(&self) -> Trait {
  |                             ^^^ not a value

error[E0425]: cannot find value `bar` in this scope
 --> 152f764c6622dfef067008fe2bb5329872ae96ed.rs:3:9
  |
3 |         bar
  |         ^^^ not found in this scope

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> <crate attribute>:1:9
  |
1 | feature(generic_const_exprs)
  |         ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: trait objects without an explicit `dyn` are deprecated
 --> 152f764c6622dfef067008fe2bb5329872ae96ed.rs:1:22
  |
1 | trait Trait<const N: Trait = bar> {
  |                      ^^^^^
  |
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
  = note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
  |
1 | trait Trait<const N: dyn Trait = bar> {
  |                      +++

error[E0391]: cycle detected when computing type of `Trait::N`
 --> 152f764c6622dfef067008fe2bb5329872ae96ed.rs:1:22
  |
1 | trait Trait<const N: Trait = bar> {
  |                      ^^^^^
  |
  = note: ...which immediately requires computing type of `Trait::N` again
note: cycle used when computing explicit predicates of trait `Trait`
 --> 152f764c6622dfef067008fe2bb5329872ae96ed.rs:1:1
  |
1 | trait Trait<const N: Trait = bar> {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0391]: cycle detected when computing type of `Trait::N`
 --> 152f764c6622dfef067008fe2bb5329872ae96ed.rs:1:13
  |
1 | trait Trait<const N: Trait = bar> {
  |             ^^^^^^^^^^^^^^^^^^^^
  |
  = note: ...which immediately requires computing type of `Trait::N` again
note: cycle used when computing explicit predicates of trait `Trait`
 --> 152f764c6622dfef067008fe2bb5329872ae96ed.rs:1:1
  |
1 | trait Trait<const N: Trait = bar> {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
 --> 152f764c6622dfef067008fe2bb5329872ae96ed.rs:2:12
  |
2 |     fn fnc<const N: Trait = u32>(&self) -> Trait {
  |            ^^^^^^^^^^^^^^^^^^^^

warning: trait objects without an explicit `dyn` are deprecated
 --> 152f764c6622dfef067008fe2bb5329872ae96ed.rs:2:21
  |
2 |     fn fnc<const N: Trait = u32>(&self) -> Trait {
  |                     ^^^^^
  |
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
  |
2 |     fn fnc<const N: dyn Trait = u32>(&self) -> Trait {
  |                     +++

warning: trait objects without an explicit `dyn` are deprecated
 --> 152f764c6622dfef067008fe2bb5329872ae96ed.rs:2:44
  |
2 |     fn fnc<const N: Trait = u32>(&self) -> Trait {
  |                                            ^^^^^
  |
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
  |
2 |     fn fnc<const N: Trait = u32>(&self) -> dyn Trait {
  |                                            +++
Backtrace


thread '<unnamed>' panicked at 'range end index 2 out of range for slice of length 1', compiler/rustc_hir_analysis/src/collect/generics_of.rs:82:34
stack backtrace:
   0:     0x7f0a4a16625a - std::backtrace_rs::backtrace::libunwind::trace::h39c51bcedb139b44
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f0a4a16625a - std::backtrace_rs::backtrace::trace_unsynchronized::h9cf890f6f509d0c3
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f0a4a16625a - std::sys_common::backtrace::_print_fmt::h4a0d7673c4689a86
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f0a4a16625a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hed99d8097fd95926
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f0a4a1c8e4e - core::fmt::write::hdab16ae0136a16af
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/core/src/fmt/mod.rs:1208:17
   5:     0x7f0a4a156675 - std::io::Write::write_fmt::h9619f0289bf5af21
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/io/mod.rs:1682:15
   6:     0x7f0a4a166025 - std::sys_common::backtrace::_print::h2fbe09348ca97657
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f0a4a166025 - std::sys_common::backtrace::print::h72058f5ceb813403
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f0a4a168d6f - std::panicking::default_hook::{{closure}}::h1542b395e584376b
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/panicking.rs:267:22
   9:     0x7f0a4a168aab - std::panicking::default_hook::hf92492522bb6bc51
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/panicking.rs:286:9
  10:     0x7f0a4a16958c - std::panicking::rust_panic_with_hook::h8e3ba576266d6126
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/panicking.rs:688:13
  11:     0x7f0a4a169329 - std::panicking::begin_panic_handler::{{closure}}::h5718d689762256a1
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/panicking.rs:579:13
  12:     0x7f0a4a16670c - std::sys_common::backtrace::__rust_end_short_backtrace::hb4469c61f2390e29
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/sys_common/backtrace.rs:137:18
  13:     0x7f0a4a169032 - rust_begin_unwind
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/panicking.rs:575:5
  14:     0x7f0a4a1c5863 - core::panicking::panic_fmt::h4dafe9d2577d7060
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/core/src/panicking.rs:64:14
  15:     0x7f0a4a1cc002 - core::slice::index::slice_end_index_len_fail_rt::h1d8f6c1e2b66432f
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/core/src/slice/index.rs:77:5
  16:     0x7f0a4a1cbf86 - core::slice::index::slice_end_index_len_fail::he6e8d5f4deaa626d
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/core/src/slice/index.rs:69:9
  17:     0x7f0a4bfce5b5 - rustc_hir_analysis[df495fcaee2748ed]::collect::generics_of::generics_of
  18:     0x7f0a4bde7e8c - rustc_query_system[c6fc551e4ef2763b]::query::plumbing::get_query::<rustc_query_impl[935dec28a6523c17]::queries::generics_of, rustc_query_impl[935dec28a6523c17]::plumbing::QueryCtxt>
  19:     0x7f0a4b9e6196 - <rustc_middle[eef20b0c23bc8b9b]::ty::list::List<rustc_middle[eef20b0c23bc8b9b]::ty::subst::GenericArg>>::identity_for_item
  20:     0x7f0a4c5bebfa - <rustc_middle[eef20b0c23bc8b9b]::ty::consts::Const>::from_opt_const_arg_anon_const
  21:     0x7f0a4ce4b7fe - rustc_middle[eef20b0c23bc8b9b]::ty::consts::const_param_default
  22:     0x7f0a4cd4543b - rustc_query_system[c6fc551e4ef2763b]::query::plumbing::try_execute_query::<rustc_query_impl[935dec28a6523c17]::plumbing::QueryCtxt, rustc_query_system[c6fc551e4ef2763b]::query::caches::DefaultCache<rustc_span[653636119034ca50]::def_id::DefId, rustc_middle[eef20b0c23bc8b9b]::ty::consts::Const>>
  23:     0x7f0a4cd45134 - rustc_query_system[c6fc551e4ef2763b]::query::plumbing::get_query::<rustc_query_impl[935dec28a6523c17]::queries::const_param_default, rustc_query_impl[935dec28a6523c17]::plumbing::QueryCtxt>
  24:     0x7f0a4bd98bc0 - <rustc_hir_analysis[df495fcaee2748ed]::collect::CollectItemTypesVisitor as rustc_hir[ba83b4f9e64fc5a4]::intravisit::Visitor>::visit_generics
  25:     0x7f0a4bda0d3e - rustc_hir[ba83b4f9e64fc5a4]::intravisit::walk_trait_item::<rustc_hir_analysis[df495fcaee2748ed]::collect::CollectItemTypesVisitor>
  26:     0x7f0a4bd9ff36 - <rustc_hir_analysis[df495fcaee2748ed]::collect::CollectItemTypesVisitor as rustc_hir[ba83b4f9e64fc5a4]::intravisit::Visitor>::visit_trait_item
  27:     0x7f0a4bd95a82 - <rustc_middle[eef20b0c23bc8b9b]::hir::map::Map>::visit_item_likes_in_module::<rustc_hir_analysis[df495fcaee2748ed]::collect::CollectItemTypesVisitor>
  28:     0x7f0a4bd9579c - rustc_hir_analysis[df495fcaee2748ed]::collect::collect_mod_item_types
  29:     0x7f0a4bff3903 - rustc_query_system[c6fc551e4ef2763b]::query::plumbing::try_execute_query::<rustc_query_impl[935dec28a6523c17]::plumbing::QueryCtxt, rustc_query_system[c6fc551e4ef2763b]::query::caches::VecCache<rustc_span[653636119034ca50]::def_id::LocalDefId, ()>>
  30:     0x7f0a4c8aa833 - rustc_query_system[c6fc551e4ef2763b]::query::plumbing::get_query::<rustc_query_impl[935dec28a6523c17]::queries::collect_mod_item_types, rustc_query_impl[935dec28a6523c17]::plumbing::QueryCtxt>
  31:     0x7f0a4b8d3b05 - <rustc_middle[eef20b0c23bc8b9b]::hir::map::Map>::for_each_module::<rustc_hir_analysis[df495fcaee2748ed]::check_crate::{closure#0}::{closure#0}::{closure#0}>
  32:     0x7f0a4b8d3198 - <rustc_session[87f0d63408877899]::session::Session>::track_errors::<rustc_hir_analysis[df495fcaee2748ed]::check_crate::{closure#0}, ()>
  33:     0x7f0a4b8d2e8f - rustc_hir_analysis[df495fcaee2748ed]::check_crate
  34:     0x7f0a4b8d2bab - rustc_interface[c57545daadc3fa09]::passes::analysis
  35:     0x7f0a4cc9a3ba - rustc_query_system[c6fc551e4ef2763b]::query::plumbing::try_execute_query::<rustc_query_impl[935dec28a6523c17]::plumbing::QueryCtxt, rustc_query_system[c6fc551e4ef2763b]::query::caches::DefaultCache<(), core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>>>
  36:     0x7f0a4cc9a0b0 - rustc_query_system[c6fc551e4ef2763b]::query::plumbing::get_query::<rustc_query_impl[935dec28a6523c17]::queries::analysis, rustc_query_impl[935dec28a6523c17]::plumbing::QueryCtxt>
  37:     0x7f0a4c64bfab - <rustc_interface[c57545daadc3fa09]::passes::QueryContext>::enter::<rustc_driver[d87acf87108c2deb]::run_compiler::{closure#1}::{closure#2}::{closure#2}, core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>>
  38:     0x7f0a4c64395e - <rustc_interface[c57545daadc3fa09]::interface::Compiler>::enter::<rustc_driver[d87acf87108c2deb]::run_compiler::{closure#1}::{closure#2}, core[ec9ef0a26f3cf28]::result::Result<core[ec9ef0a26f3cf28]::option::Option<rustc_interface[c57545daadc3fa09]::queries::Linker>, rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>>
  39:     0x7f0a4c63e978 - rustc_span[653636119034ca50]::with_source_map::<core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>, rustc_interface[c57545daadc3fa09]::interface::run_compiler<core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>, rustc_driver[d87acf87108c2deb]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  40:     0x7f0a4c63e465 - <scoped_tls[2510ce566f7fd87d]::ScopedKey<rustc_span[653636119034ca50]::SessionGlobals>>::set::<rustc_interface[c57545daadc3fa09]::interface::run_compiler<core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>, rustc_driver[d87acf87108c2deb]::run_compiler::{closure#1}>::{closure#0}, core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>>
  41:     0x7f0a4c63da52 - std[b988c8daa9554a2a]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c57545daadc3fa09]::util::run_in_thread_pool_with_globals<rustc_interface[c57545daadc3fa09]::interface::run_compiler<core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>, rustc_driver[d87acf87108c2deb]::run_compiler::{closure#1}>::{closure#0}, core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>>
  42:     0x7f0a4cda6848 - <<std[b988c8daa9554a2a]::thread::Builder>::spawn_unchecked_<rustc_interface[c57545daadc3fa09]::util::run_in_thread_pool_with_globals<rustc_interface[c57545daadc3fa09]::interface::run_compiler<core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>, rustc_driver[d87acf87108c2deb]::run_compiler::{closure#1}>::{closure#0}, core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ec9ef0a26f3cf28]::result::Result<(), rustc_errors[57b9e96b8e7428c]::ErrorGuaranteed>>::{closure#1} as core[ec9ef0a26f3cf28]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x7f0a4e2b07f3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd24e4095bea58fc3
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/alloc/src/boxed.rs:2000:9
  44:     0x7f0a4e2b07f3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7c7f47af88aff778
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/alloc/src/boxed.rs:2000:9
  45:     0x7f0a4e2b07f3 - std::sys::unix::thread::Thread::new::thread_start::h8d5de08b8b3f2cac
                               at /rustc/23415176968e81e0aac92d0218612a89c4e68a82/library/std/src/sys/unix/thread.rs:108:17
  46:     0x7f0a49f068fd - <unknown>
  47:     0x7f0a49f88a60 - <unknown>
  48:                0x0 - <unknown>
error: aborting due to 7 previous errors; 4 warnings emitted

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Dec 4, 2022
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Dec 7, 2022

A little bit smaller example:

#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

trait Trait<T> {
    fn fnc<const N: usize = "">(&self) {}
}

fn main() {}

playground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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.

2 participants