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

Const generics out of range when substituting substs=[] #101036

Closed
Tracked by #106994
DutchGhost opened this issue Aug 26, 2022 · 6 comments
Closed
Tracked by #106994

Const generics out of range when substituting substs=[] #101036

DutchGhost opened this issue Aug 26, 2022 · 6 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` glacier ICE tracked in rust-lang/glacier. 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.

Comments

@DutchGhost
Copy link
Contributor

DutchGhost commented Aug 26, 2022

This issue does NOT occur on nightly, so perhaps it's a duplicate that has already been fixed, but I could not find a similar issue on github. Feel free to close if this has already been fixed :)

Code

#[repr(u8)]
enum T<const N: u8 = { T::<0>::A as u8 + T::<0>::B as u8 }> {
    A = 1, B
}

Meta

rustc --version --verbose:

rustc 1.63.0

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:639:17: const parameter `N/#0` (Const { ty: u8, kind: Param(N/#0) }/0) out of range when substituting substs=[]
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/compiler/rustc_errors/src/lib.rs:1331:9
stack backtrace:
   0:     0x7f349653818d - std::backtrace_rs::backtrace::libunwind::trace::h8217d0a8f3fd2f41
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f349653818d - std::backtrace_rs::backtrace::trace_unsynchronized::h308103876b3af410
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f349653818d - std::sys_common::backtrace::_print_fmt::hc208018c6153605e
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f349653818d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf89a7ed694dfb585
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f3496593f7c - core::fmt::write::h21038c1382fe4264
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/fmt/mod.rs:1197:17
   5:     0x7f34965298a1 - std::io::Write::write_fmt::h7dbb1c9a3c254aef
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/io/mod.rs:1672:15
   6:     0x7f349653ae55 - std::sys_common::backtrace::_print::h4e8889719c9ddeb8
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f349653ae55 - std::sys_common::backtrace::print::h1506fe2cb3022667
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f349653ae55 - std::panicking::default_hook::{{closure}}::hd9d7ce2a8a782440
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:295:22
   9:     0x7f349653ab76 - std::panicking::default_hook::h5b16ec25444b1b5d
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:314:9
  10:     0x7f3496d15b54 - rustc_driver[e01eec72899701d3]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f349653b52a - std::panicking::rust_panic_with_hook::hb0138cb6e6fea3e4
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:702:17
  12:     0x7f3497d28c91 - std[f9ee9c7d4fd68eda]::panicking::begin_panic::<rustc_errors[b2e8492a1747ee42]::ExplicitBug>::{closure#0}
  13:     0x7f3497d285e6 - std[f9ee9c7d4fd68eda]::sys_common::backtrace::__rust_end_short_backtrace::<std[f9ee9c7d4fd68eda]::panicking::begin_panic<rustc_errors[b2e8492a1747ee42]::ExplicitBug>::{closure#0}, !>
  14:     0x7f3497d6e796 - std[f9ee9c7d4fd68eda]::panicking::begin_panic::<rustc_errors[b2e8492a1747ee42]::ExplicitBug>
  15:     0x7f3497d13446 - std[f9ee9c7d4fd68eda]::panic::panic_any::<rustc_errors[b2e8492a1747ee42]::ExplicitBug>
  16:     0x7f3497d11061 - <rustc_errors[b2e8492a1747ee42]::HandlerInner>::span_bug::<rustc_span[fb9cf5df1e5e5539]::span_encoding::Span, &alloc[59e4fb8ddcfb913c]::string::String>
  17:     0x7f3497d10f20 - <rustc_errors[b2e8492a1747ee42]::Handler>::span_bug::<rustc_span[fb9cf5df1e5e5539]::span_encoding::Span, &alloc[59e4fb8ddcfb913c]::string::String>
  18:     0x7f3497de8fb8 - rustc_middle[6ba33e07887d312d]::ty::context::tls::with_opt::<rustc_middle[6ba33e07887d312d]::util::bug::opt_span_bug_fmt<rustc_span[fb9cf5df1e5e5539]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7f3497de9cb6 - rustc_middle[6ba33e07887d312d]::util::bug::opt_span_bug_fmt::<rustc_span[fb9cf5df1e5e5539]::span_encoding::Span>
  20:     0x7f3497de9c74 - rustc_middle[6ba33e07887d312d]::util::bug::span_bug_fmt::<rustc_span[fb9cf5df1e5e5539]::span_encoding::Span>
  21:     0x7f3498d84a64 - <rustc_middle[6ba33e07887d312d]::ty::consts::Const as rustc_middle[6ba33e07887d312d]::ty::fold::TypeFoldable>::try_fold_with::<rustc_middle[6ba33e07887d312d]::ty::subst::SubstFolder>
  22:     0x7f3498dd769e - <rustc_middle[6ba33e07887d312d]::ty::subst::SubstFolder as rustc_middle[6ba33e07887d312d]::ty::fold::TypeFolder>::fold_const
  23:     0x7f34992ed2a7 - <rustc_const_eval[fe641159a34c486c]::interpret::eval_context::InterpCx<rustc_const_eval[fe641159a34c486c]::const_eval::machine::CompileTimeInterpreter>>::subst_from_current_frame_and_normalize_erasing_regions::<rustc_middle[6ba33e07887d312d]::mir::ConstantKind>
  24:     0x7f3498761f67 - <rustc_const_eval[fe641159a34c486c]::interpret::eval_context::InterpCx<rustc_const_eval[fe641159a34c486c]::const_eval::machine::CompileTimeInterpreter>>::push_stack_frame
  25:     0x7f34987a0243 - rustc_const_eval[fe641159a34c486c]::const_eval::eval_queries::eval_to_allocation_raw_provider
  26:     0x7f34988bc4a7 - rustc_query_system[141d649b4129d34f]::query::plumbing::try_execute_query::<rustc_query_impl[f9d56364e2ba3b26]::plumbing::QueryCtxt, rustc_query_system[141d649b4129d34f]::query::caches::DefaultCache<rustc_middle[6ba33e07887d312d]::ty::ParamEnvAnd<rustc_middle[6ba33e07887d312d]::mir::interpret::GlobalId>, core[3edb0f9afb6adb32]::result::Result<rustc_middle[6ba33e07887d312d]::mir::interpret::value::ConstAlloc, rustc_middle[6ba33e07887d312d]::mir::interpret::error::ErrorHandled>>>
  27:     0x7f34988a87f3 - <rustc_query_impl[f9d56364e2ba3b26]::Queries as rustc_middle[6ba33e07887d312d]::ty::query::QueryEngine>::eval_to_allocation_raw
  28:     0x7f3499320e15 - rustc_const_eval[fe641159a34c486c]::const_eval::eval_to_valtree
  29:     0x7f3499324530 - <rustc_const_eval[fe641159a34c486c]::provide::{closure#1} as core[3edb0f9afb6adb32]::ops::function::FnOnce<(rustc_middle[6ba33e07887d312d]::ty::context::TyCtxt, rustc_middle[6ba33e07887d312d]::ty::ParamEnvAnd<rustc_middle[6ba33e07887d312d]::mir::interpret::GlobalId>)>>::call_once
  30:     0x7f349948990b - rustc_query_system[141d649b4129d34f]::query::plumbing::get_query::<rustc_query_impl[f9d56364e2ba3b26]::queries::eval_to_valtree, rustc_query_impl[f9d56364e2ba3b26]::plumbing::QueryCtxt>
  31:     0x7f34993ef875 - <rustc_query_impl[f9d56364e2ba3b26]::Queries as rustc_middle[6ba33e07887d312d]::ty::query::QueryEngine>::eval_to_valtree
  32:     0x7f349973a047 - <rustc_middle[6ba33e07887d312d]::ty::context::TyCtxt>::const_eval_global_id_for_typeck
  33:     0x7f3499739c8b - <rustc_middle[6ba33e07887d312d]::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  34:     0x7f34996b76d9 - <rustc_infer[dac8c065ff7906eb]::infer::InferCtxt>::const_eval_resolve
  35:     0x7f34996a370a - rustc_trait_selection[a24496718f2f9ce]::traits::const_evaluatable::is_const_evaluatable
  36:     0x7f3498c06c07 - <rustc_trait_selection[a24496718f2f9ce]::traits::fulfill::FulfillProcessor as rustc_data_structures[a72e3ab837655e00]::obligation_forest::ObligationProcessor>::process_obligation
  37:     0x7f3498c54db3 - <rustc_data_structures[a72e3ab837655e00]::obligation_forest::ObligationForest<rustc_trait_selection[a24496718f2f9ce]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[a24496718f2f9ce]::traits::fulfill::FulfillProcessor, rustc_data_structures[a72e3ab837655e00]::obligation_forest::Outcome<rustc_trait_selection[a24496718f2f9ce]::traits::fulfill::PendingPredicateObligation, rustc_infer[dac8c065ff7906eb]::traits::FulfillmentErrorCode>>
  38:     0x7f3498c00570 - <rustc_trait_selection[a24496718f2f9ce]::traits::fulfill::FulfillmentContext as rustc_infer[dac8c065ff7906eb]::traits::engine::TraitEngine>::select_all_or_error
  39:     0x7f34982de46c - <rustc_typeck[4304dccefed204b7]::check::fn_ctxt::FnCtxt>::select_all_obligations_or_error
  40:     0x7f349918ea35 - <rustc_infer[dac8c065ff7906eb]::infer::InferCtxtBuilder>::enter::<(), <rustc_typeck[4304dccefed204b7]::check::inherited::InheritedBuilder>::enter<<rustc_typeck[4304dccefed204b7]::check::wfcheck::CheckWfFcxBuilder>::with_fcx<rustc_typeck[4304dccefed204b7]::check::wfcheck::check_type_defn<rustc_typeck[4304dccefed204b7]::check::wfcheck::check_item_well_formed::{closure#4}>::{closure#0}>::{closure#0}, ()>::{closure#0}>
  41:     0x7f34983d9a0b - rustc_typeck[4304dccefed204b7]::check::wfcheck::check_item_well_formed
  42:     0x7f34988d4df6 - rustc_query_system[141d649b4129d34f]::query::plumbing::try_execute_query::<rustc_query_impl[f9d56364e2ba3b26]::plumbing::QueryCtxt, rustc_query_system[141d649b4129d34f]::query::caches::DefaultCache<rustc_span[fb9cf5df1e5e5539]::def_id::LocalDefId, ()>>
  43:     0x7f34988a9cc1 - <rustc_query_impl[f9d56364e2ba3b26]::Queries as rustc_middle[6ba33e07887d312d]::ty::query::QueryEngine>::check_item_well_formed
  44:     0x7f34983c29f6 - <rustc_middle[6ba33e07887d312d]::hir::map::Map>::par_visit_all_item_likes::<rustc_typeck[4304dccefed204b7]::check::wfcheck::CheckTypeWellFormedVisitor>
  45:     0x7f34991ab0f7 - <rustc_session[72c90254a58d88d1]::session::Session>::track_errors::<rustc_typeck[4304dccefed204b7]::check_crate::{closure#5}, ()>
  46:     0x7f349918705b - rustc_typeck[4304dccefed204b7]::check_crate
  47:     0x7f3498ef86b7 - rustc_interface[be6c6c80f2cd8cf2]::passes::analysis
  48:     0x7f34994587bf - rustc_query_system[141d649b4129d34f]::query::plumbing::try_execute_query::<rustc_query_impl[f9d56364e2ba3b26]::plumbing::QueryCtxt, rustc_query_system[141d649b4129d34f]::query::caches::DefaultCache<(), core[3edb0f9afb6adb32]::result::Result<(), rustc_errors[b2e8492a1747ee42]::ErrorGuaranteed>>>
  49:     0x7f34994a29fe - rustc_query_system[141d649b4129d34f]::query::plumbing::get_query::<rustc_query_impl[f9d56364e2ba3b26]::queries::analysis, rustc_query_impl[f9d56364e2ba3b26]::plumbing::QueryCtxt>
  50:     0x7f3498edbf87 - <rustc_interface[be6c6c80f2cd8cf2]::passes::QueryContext>::enter::<rustc_driver[e01eec72899701d3]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[3edb0f9afb6adb32]::result::Result<(), rustc_errors[b2e8492a1747ee42]::ErrorGuaranteed>>
  51:     0x7f3498ec646f - <rustc_interface[be6c6c80f2cd8cf2]::interface::Compiler>::enter::<rustc_driver[e01eec72899701d3]::run_compiler::{closure#1}::{closure#2}, core[3edb0f9afb6adb32]::result::Result<core[3edb0f9afb6adb32]::option::Option<rustc_interface[be6c6c80f2cd8cf2]::queries::Linker>, rustc_errors[b2e8492a1747ee42]::ErrorGuaranteed>>
  52:     0x7f3498ebfa7f - rustc_span[fb9cf5df1e5e5539]::with_source_map::<core[3edb0f9afb6adb32]::result::Result<(), rustc_errors[b2e8492a1747ee42]::ErrorGuaranteed>, rustc_interface[be6c6c80f2cd8cf2]::interface::create_compiler_and_run<core[3edb0f9afb6adb32]::result::Result<(), rustc_errors[b2e8492a1747ee42]::ErrorGuaranteed>, rustc_driver[e01eec72899701d3]::run_compiler::{closure#1}>::{closure#1}>
  53:     0x7f3498ec7302 - <scoped_tls[134a193f706323ee]::ScopedKey<rustc_span[fb9cf5df1e5e5539]::SessionGlobals>>::set::<rustc_interface[be6c6c80f2cd8cf2]::interface::run_compiler<core[3edb0f9afb6adb32]::result::Result<(), rustc_errors[b2e8492a1747ee42]::ErrorGuaranteed>, rustc_driver[e01eec72899701d3]::run_compiler::{closure#1}>::{closure#0}, core[3edb0f9afb6adb32]::result::Result<(), rustc_errors[b2e8492a1747ee42]::ErrorGuaranteed>>
  54:     0x7f3498eea99f - std[f9ee9c7d4fd68eda]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[be6c6c80f2cd8cf2]::util::run_in_thread_pool_with_globals<rustc_interface[be6c6c80f2cd8cf2]::interface::run_compiler<core[3edb0f9afb6adb32]::result::Result<(), rustc_errors[b2e8492a1747ee42]::ErrorGuaranteed>, rustc_driver[e01eec72899701d3]::run_compiler::{closure#1}>::{closure#0}, core[3edb0f9afb6adb32]::result::Result<(), rustc_errors[b2e8492a1747ee42]::ErrorGuaranteed>>::{closure#0}, core[3edb0f9afb6adb32]::result::Result<(), rustc_errors[b2e8492a1747ee42]::ErrorGuaranteed>>
  55:     0x7f3498edc529 - <<std[f9ee9c7d4fd68eda]::thread::Builder>::spawn_unchecked_<rustc_interface[be6c6c80f2cd8cf2]::util::run_in_thread_pool_with_globals<rustc_interface[be6c6c80f2cd8cf2]::interface::run_compiler<core[3edb0f9afb6adb32]::result::Result<(), rustc_errors[b2e8492a1747ee42]::ErrorGuaranteed>, rustc_driver[e01eec72899701d3]::run_compiler::{closure#1}>::{closure#0}, core[3edb0f9afb6adb32]::result::Result<(), rustc_errors[b2e8492a1747ee42]::ErrorGuaranteed>>::{closure#0}, core[3edb0f9afb6adb32]::result::Result<(), rustc_errors[b2e8492a1747ee42]::ErrorGuaranteed>>::{closure#1} as core[3edb0f9afb6adb32]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  56:     0x7f3496545463 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1680342795a2dc08
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/boxed.rs:1951:9
  57:     0x7f3496545463 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h45204a69827b0e83
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/boxed.rs:1951:9
  58:     0x7f3496545463 - std::sys::unix::thread::Thread::new::thread_start::h5d4e11bbda4161c8
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys/unix/thread.rs:108:17
  59:     0x7f349646b609 - start_thread
  60:     0x7f349638e133 - clone
  61:                0x0 - <unknown>

@DutchGhost DutchGhost 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 Aug 26, 2022
@DutchGhost
Copy link
Contributor Author

Some tweaks are required to make it ICE on nightly rustc 1.65.0-nightly (86c6ebe 2022-08-16):

#![feature(generic_const_exprs)]

const fn t<const N: usize>() -> u8 {
    N as u8
}

#[repr(u8)]
enum T<const N: u8 = { T::<0>::A as u8 + T::<0>::B as u8 }>
where
    [(); N as usize]:
{
    A = t::<N>() as u8, B
}

@b-naber
Copy link
Contributor

b-naber commented Aug 26, 2022

#98429 might have solved the ICE in the first example. Will try to look into the second example on the weekend.

@b-naber
Copy link
Contributor

b-naber commented Aug 30, 2022

#86580 Seems to be the cause of this. Didn't find a way to properly fix this, i.e. without causing the problem that that PR was trying to fix to re-occur.

@steffahn
Copy link
Member

steffahn commented Sep 5, 2022

So this issue requires the generic_const_exprs feature to reproduce on nightly? If yes, I’d like to tag it accordingly :-)

@BoxyUwU BoxyUwU added the F-generic_const_exprs `#![feature(generic_const_exprs)]` label Dec 5, 2022
@Rageking8
Copy link
Contributor

Another repro for the same ICE msg:

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

struct S<const N: usize = ()>()
where [(); N]: ;

fn main() {}

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 17, 2023

closing in favor of #106994

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` glacier ICE tracked in rust-lang/glacier. 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.
Projects
None yet
Development

No branches or pull requests

6 participants