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

subst ICE when building specialization graph with generic_const_exprs #106473

Closed
Tracked by #106994
compiler-errors opened this issue Jan 4, 2023 · 3 comments
Closed
Tracked by #106994
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

@compiler-errors
Copy link
Member

compiler-errors commented Jan 4, 2023

I'm pretty sure this is a minimization of the ICE in #105573, cc @peter-kehl.

playground:

#![feature(generic_const_exprs)]

const DEFAULT: u32 = 1;

struct V<const U: usize = DEFAULT>
where
    [(); U]:;

trait Tr {}

impl Tr for V {}
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/lib.rs:1:12
  |
1 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: [see issue #76560 <https://github.com/rust-lang/rust/issues/76560>](https://github.com/rust-lang/rust/issues/76560) for more information
  = note: `#[warn(incomplete_features)]` on by default

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:877:9: const parameter `U/#0` (Const { ty: usize, kind: Param(U/#0) }/0) out of range when substituting substs=[]

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/c7572670a1302f5c7e245d069200e22da9df0316/compiler/rustc_errors/src/lib.rs:1587:9
stack backtrace:
   0:     0x7fb3276c623a - std::backtrace_rs::backtrace::libunwind::trace::hde7ade2d456779d5
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fb3276c623a - std::backtrace_rs::backtrace::trace_unsynchronized::hfa80a5b1dd6480ee
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fb3276c623a - std::sys_common::backtrace::_print_fmt::hdc0ec1456830cd06
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7fb3276c623a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd13f10ad14103748
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fb3277293fe - core::fmt::write::h04362bd8a0a29086
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/core/src/fmt/mod.rs:1208:17
   5:     0x7fb3276b6715 - std::io::Write::write_fmt::h6d8d0e4c63711392
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/io/mod.rs:1682:15
   6:     0x7fb3276c6005 - std::sys_common::backtrace::_print::hdc928731f1397a06
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7fb3276c6005 - std::sys_common::backtrace::print::h211d1fcb56b81f1a
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7fb3276c8dcf - std::panicking::default_hook::{{closure}}::hfa505880d91d52f8
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/panicking.rs:267:22
   9:     0x7fb3276c8b0b - std::panicking::default_hook::h8786c12ebfe50d1b
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/panicking.rs:286:9
  10:     0x7fb32a9d83c4 - rustc_driver[37eb5d1b4ab0972a]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7fb3276c960d - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h5476bb179a602163
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/alloc/src/boxed.rs:2002:9
  12:     0x7fb3276c960d - std::panicking::rust_panic_with_hook::h29b0a852719ddece
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/panicking.rs:692:13
  13:     0x7fb32ae9d841 - std[d0bfc7d2f365d785]::panicking::begin_panic::<rustc_errors[385c082a2444c46]::ExplicitBug>::{closure#0}
  14:     0x7fb32ae9c726 - std[d0bfc7d2f365d785]::sys_common::backtrace::__rust_end_short_backtrace::<std[d0bfc7d2f365d785]::panicking::begin_panic<rustc_errors[385c082a2444c46]::ExplicitBug>::{closure#0}, !>
  15:     0x7fb32af4f156 - std[d0bfc7d2f365d785]::panicking::begin_panic::<rustc_errors[385c082a2444c46]::ExplicitBug>
  16:     0x7fb32aec5836 - std[d0bfc7d2f365d785]::panic::panic_any::<rustc_errors[385c082a2444c46]::ExplicitBug>
  17:     0x7fb32aec2cf6 - <rustc_errors[385c082a2444c46]::HandlerInner>::bug::<&alloc[30c4eaa39988362f]::string::String>
  18:     0x7fb32aec2950 - <rustc_errors[385c082a2444c46]::Handler>::bug::<&alloc[30c4eaa39988362f]::string::String>
  19:     0x7fb32af36fde - rustc_middle[f0169fe793b61df1]::ty::context::tls::with_context_opt::<rustc_middle[f0169fe793b61df1]::ty::context::tls::with_opt<rustc_middle[f0169fe793b61df1]::util::bug::opt_span_bug_fmt<rustc_span[4c3f4c74ffe41368]::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
  20:     0x7fb32af37c66 - rustc_middle[f0169fe793b61df1]::util::bug::opt_span_bug_fmt::<rustc_span[4c3f4c74ffe41368]::span_encoding::Span>
  21:     0x7fb328b7e093 - rustc_middle[f0169fe793b61df1]::util::bug::bug_fmt
  22:     0x7fb32aef3a9e - <rustc_middle[f0169fe793b61df1]::ty::subst::SubstFolder>::const_param_out_of_range
  23:     0x7fb32894975c - <rustc_middle[f0169fe793b61df1]::ty::subst::SubstFolder as rustc_middle[f0169fe793b61df1]::ty::fold::TypeFolder>::fold_const
  24:     0x7fb328982c1b - <rustc_middle[f0169fe793b61df1]::ty::subst::SubstFolder as rustc_middle[f0169fe793b61df1]::ty::fold::FallibleTypeFolder>::try_fold_ty
  25:     0x7fb32aef17cc - <rustc_middle[f0169fe793b61df1]::ty::subst::GenericArg as rustc_middle[f0169fe793b61df1]::ty::fold::TypeFoldable>::try_fold_with::<rustc_middle[f0169fe793b61df1]::ty::subst::SubstFolder>
  26:     0x7fb328a0d587 - <rustc_middle[f0169fe793b61df1]::ty::generics::GenericPredicates>::instantiate_into
  27:     0x7fb3290cfcfa - <rustc_trait_selection[9ab53f0af56327e9]::traits::wf::WfPredicates>::nominal_obligations_inner
  28:     0x7fb3290cd313 - <rustc_trait_selection[9ab53f0af56327e9]::traits::wf::WfPredicates>::compute
  29:     0x7fb328b43f16 - <rustc_trait_selection[9ab53f0af56327e9]::traits::fulfill::FulfillProcessor as rustc_data_structures[6bf8f914372919d6]::obligation_forest::ObligationProcessor>::process_obligation
  30:     0x7fb328b40ed2 - <rustc_data_structures[6bf8f914372919d6]::obligation_forest::ObligationForest<rustc_trait_selection[9ab53f0af56327e9]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[9ab53f0af56327e9]::traits::fulfill::FulfillProcessor>
  31:     0x7fb328eca896 - <rustc_trait_selection[9ab53f0af56327e9]::traits::engine::ObligationCtxt>::select_all_or_error
  32:     0x7fb32963d760 - rustc_hir_analysis[154c1a05a8643cc4]::check::wfcheck::check_type_defn
  33:     0x7fb32961f9e1 - rustc_hir_analysis[154c1a05a8643cc4]::check::wfcheck::check_well_formed
  34:     0x7fb3291d903b - rustc_query_system[91a2545c0f12e962]::query::plumbing::get_query::<rustc_query_impl[c17f0eee1516a7cd]::queries::check_well_formed, rustc_query_impl[c17f0eee1516a7cd]::plumbing::QueryCtxt, rustc_middle[f0169fe793b61df1]::dep_graph::dep_node::DepKind>
  35:     0x7fb329e1e3a8 - rustc_data_structures[6bf8f914372919d6]::sync::par_for_each_in::<&[rustc_hir[3fb8fe55df620ea3]::hir::ItemId], <rustc_middle[f0169fe793b61df1]::hir::ModuleItems>::par_items<rustc_hir_analysis[154c1a05a8643cc4]::check::wfcheck::check_mod_type_wf::{closure#0}>::{closure#0}>
  36:     0x7fb329e1e1b7 - rustc_hir_analysis[154c1a05a8643cc4]::check::wfcheck::check_mod_type_wf
  37:     0x7fb329f779a1 - rustc_query_system[91a2545c0f12e962]::query::plumbing::try_execute_query::<rustc_query_impl[c17f0eee1516a7cd]::queries::check_mod_type_wf, rustc_query_impl[c17f0eee1516a7cd]::plumbing::QueryCtxt>
  38:     0x7fb329f773ad - <rustc_query_impl[c17f0eee1516a7cd]::Queries as rustc_middle[f0169fe793b61df1]::ty::query::QueryEngine>::check_mod_type_wf
  39:     0x7fb328dff588 - rustc_data_structures[6bf8f914372919d6]::sync::par_for_each_in::<&[rustc_hir[3fb8fe55df620ea3]::hir_id::OwnerId], <rustc_middle[f0169fe793b61df1]::hir::map::Map>::par_for_each_module<rustc_hir_analysis[154c1a05a8643cc4]::check_crate::{closure#5}::{closure#0}::{closure#0}>::{closure#0}>
  40:     0x7fb328dff373 - <rustc_session[a4ebe106e65405ac]::session::Session>::track_errors::<rustc_hir_analysis[154c1a05a8643cc4]::check_crate::{closure#5}, ()>
  41:     0x7fb328dff09a - rustc_hir_analysis[154c1a05a8643cc4]::check_crate
  42:     0x7fb328dfed3b - rustc_interface[aa88283fbb917e58]::passes::analysis
  43:     0x7fb32a1243fe - rustc_query_system[91a2545c0f12e962]::query::plumbing::try_execute_query::<rustc_query_impl[c17f0eee1516a7cd]::queries::analysis, rustc_query_impl[c17f0eee1516a7cd]::plumbing::QueryCtxt>
  44:     0x7fb32a3a179a - <rustc_query_impl[c17f0eee1516a7cd]::Queries as rustc_middle[f0169fe793b61df1]::ty::query::QueryEngine>::analysis
  45:     0x7fb329c24163 - <rustc_interface[aa88283fbb917e58]::passes::QueryContext>::enter::<rustc_driver[37eb5d1b4ab0972a]::run_compiler::{closure#1}::{closure#2}::{closure#2}, core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>>
  46:     0x7fb329c20693 - <rustc_interface[aa88283fbb917e58]::interface::Compiler>::enter::<rustc_driver[37eb5d1b4ab0972a]::run_compiler::{closure#1}::{closure#2}, core[bb4875f5a2cb5848]::result::Result<core[bb4875f5a2cb5848]::option::Option<rustc_interface[aa88283fbb917e58]::queries::Linker>, rustc_errors[385c082a2444c46]::ErrorGuaranteed>>
  47:     0x7fb329c1b678 - rustc_span[4c3f4c74ffe41368]::with_source_map::<core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>, rustc_interface[aa88283fbb917e58]::interface::run_compiler<core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>, rustc_driver[37eb5d1b4ab0972a]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  48:     0x7fb329c1b165 - <scoped_tls[775b62078ed86023]::ScopedKey<rustc_span[4c3f4c74ffe41368]::SessionGlobals>>::set::<rustc_interface[aa88283fbb917e58]::interface::run_compiler<core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>, rustc_driver[37eb5d1b4ab0972a]::run_compiler::{closure#1}>::{closure#0}, core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>>
  49:     0x7fb329c1a752 - std[d0bfc7d2f365d785]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[aa88283fbb917e58]::util::run_in_thread_pool_with_globals<rustc_interface[aa88283fbb917e58]::interface::run_compiler<core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>, rustc_driver[37eb5d1b4ab0972a]::run_compiler::{closure#1}>::{closure#0}, core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>>
  50:     0x7fb32a2a863a - <<std[d0bfc7d2f365d785]::thread::Builder>::spawn_unchecked_<rustc_interface[aa88283fbb917e58]::util::run_in_thread_pool_with_globals<rustc_interface[aa88283fbb917e58]::interface::run_compiler<core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>, rustc_driver[37eb5d1b4ab0972a]::run_compiler::{closure#1}>::{closure#0}, core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>>::{closure#1} as core[bb4875f5a2cb5848]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  51:     0x7fb3276d3a43 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h21ad39807731e3a4
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/alloc/src/boxed.rs:1988:9
  52:     0x7fb3276d3a43 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd46fbc14280dbb64
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/alloc/src/boxed.rs:1988:9
  53:     0x7fb3276d3a43 - std::sys::unix::thread::Thread::new::thread_start::h25ae217bcd9d33ca
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/sys/unix/thread.rs:108:17
  54:     0x7fb327597609 - start_thread
  55:     0x7fb3274ba133 - clone
  56:                0x0 - <unknown>

note: 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: rustc 1.68.0-nightly (c7572670a 2023-01-03) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [check_well_formed] checking that `V` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
thread 'rustc' panicked at 'Box<dyn Any>', /rustc/c7572670a1302f5c7e245d069200e22da9df0316/compiler/rustc_errors/src/lib.rs:1587:9
stack backtrace:
   0:     0x7fb3276c623a - std::backtrace_rs::backtrace::libunwind::trace::hde7ade2d456779d5
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fb3276c623a - std::backtrace_rs::backtrace::trace_unsynchronized::hfa80a5b1dd6480ee
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fb3276c623a - std::sys_common::backtrace::_print_fmt::hdc0ec1456830cd06
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7fb3276c623a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd13f10ad14103748
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fb3277293fe - core::fmt::write::h04362bd8a0a29086
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/core/src/fmt/mod.rs:1208:17
   5:     0x7fb3276b6715 - std::io::Write::write_fmt::h6d8d0e4c63711392
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/io/mod.rs:1682:15
   6:     0x7fb3276c6005 - std::sys_common::backtrace::_print::hdc928731f1397a06
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7fb3276c6005 - std::sys_common::backtrace::print::h211d1fcb56b81f1a
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7fb3276c8dcf - std::panicking::default_hook::{{closure}}::hfa505880d91d52f8
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/panicking.rs:267:22
   9:     0x7fb3276c8b0b - std::panicking::default_hook::h8786c12ebfe50d1b
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/panicking.rs:286:9
  10:     0x7fb32a9d83c4 - rustc_driver[37eb5d1b4ab0972a]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7fb3276c960d - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h5476bb179a602163
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/alloc/src/boxed.rs:2002:9
  12:     0x7fb3276c960d - std::panicking::rust_panic_with_hook::h29b0a852719ddece
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/panicking.rs:692:13
  13:     0x7fb32ae9d841 - std[d0bfc7d2f365d785]::panicking::begin_panic::<rustc_errors[385c082a2444c46]::ExplicitBug>::{closure#0}
  14:     0x7fb32ae9c726 - std[d0bfc7d2f365d785]::sys_common::backtrace::__rust_end_short_backtrace::<std[d0bfc7d2f365d785]::panicking::begin_panic<rustc_errors[385c082a2444c46]::ExplicitBug>::{closure#0}, !>
  15:     0x7fb32af4f156 - std[d0bfc7d2f365d785]::panicking::begin_panic::<rustc_errors[385c082a2444c46]::ExplicitBug>
  16:     0x7fb32aec5836 - std[d0bfc7d2f365d785]::panic::panic_any::<rustc_errors[385c082a2444c46]::ExplicitBug>
  17:     0x7fb32aec2cf6 - <rustc_errors[385c082a2444c46]::HandlerInner>::bug::<&alloc[30c4eaa39988362f]::string::String>
  18:     0x7fb32aec2950 - <rustc_errors[385c082a2444c46]::Handler>::bug::<&alloc[30c4eaa39988362f]::string::String>
  19:     0x7fb32af36fde - rustc_middle[f0169fe793b61df1]::ty::context::tls::with_context_opt::<rustc_middle[f0169fe793b61df1]::ty::context::tls::with_opt<rustc_middle[f0169fe793b61df1]::util::bug::opt_span_bug_fmt<rustc_span[4c3f4c74ffe41368]::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
  20:     0x7fb32af37c66 - rustc_middle[f0169fe793b61df1]::util::bug::opt_span_bug_fmt::<rustc_span[4c3f4c74ffe41368]::span_encoding::Span>
  21:     0x7fb328b7e093 - rustc_middle[f0169fe793b61df1]::util::bug::bug_fmt
  22:     0x7fb32aef3a9e - <rustc_middle[f0169fe793b61df1]::ty::subst::SubstFolder>::const_param_out_of_range
  23:     0x7fb32894975c - <rustc_middle[f0169fe793b61df1]::ty::subst::SubstFolder as rustc_middle[f0169fe793b61df1]::ty::fold::TypeFolder>::fold_const
  24:     0x7fb328982c1b - <rustc_middle[f0169fe793b61df1]::ty::subst::SubstFolder as rustc_middle[f0169fe793b61df1]::ty::fold::FallibleTypeFolder>::try_fold_ty
  25:     0x7fb32aef17cc - <rustc_middle[f0169fe793b61df1]::ty::subst::GenericArg as rustc_middle[f0169fe793b61df1]::ty::fold::TypeFoldable>::try_fold_with::<rustc_middle[f0169fe793b61df1]::ty::subst::SubstFolder>
  26:     0x7fb328a0d587 - <rustc_middle[f0169fe793b61df1]::ty::generics::GenericPredicates>::instantiate_into
  27:     0x7fb3290cfcfa - <rustc_trait_selection[9ab53f0af56327e9]::traits::wf::WfPredicates>::nominal_obligations_inner
  28:     0x7fb3290cd313 - <rustc_trait_selection[9ab53f0af56327e9]::traits::wf::WfPredicates>::compute
  29:     0x7fb328b43f16 - <rustc_trait_selection[9ab53f0af56327e9]::traits::fulfill::FulfillProcessor as rustc_data_structures[6bf8f914372919d6]::obligation_forest::ObligationProcessor>::process_obligation
  30:     0x7fb328b40ed2 - <rustc_data_structures[6bf8f914372919d6]::obligation_forest::ObligationForest<rustc_trait_selection[9ab53f0af56327e9]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[9ab53f0af56327e9]::traits::fulfill::FulfillProcessor>
  31:     0x7fb328eca896 - <rustc_trait_selection[9ab53f0af56327e9]::traits::engine::ObligationCtxt>::select_all_or_error
  32:     0x7fb32961f6bf - rustc_hir_analysis[154c1a05a8643cc4]::check::wfcheck::check_well_formed
  33:     0x7fb3291d903b - rustc_query_system[91a2545c0f12e962]::query::plumbing::get_query::<rustc_query_impl[c17f0eee1516a7cd]::queries::check_well_formed, rustc_query_impl[c17f0eee1516a7cd]::plumbing::QueryCtxt, rustc_middle[f0169fe793b61df1]::dep_graph::dep_node::DepKind>
  34:     0x7fb329e1e3a8 - rustc_data_structures[6bf8f914372919d6]::sync::par_for_each_in::<&[rustc_hir[3fb8fe55df620ea3]::hir::ItemId], <rustc_middle[f0169fe793b61df1]::hir::ModuleItems>::par_items<rustc_hir_analysis[154c1a05a8643cc4]::check::wfcheck::check_mod_type_wf::{closure#0}>::{closure#0}>
  35:     0x7fb329e1e1b7 - rustc_hir_analysis[154c1a05a8643cc4]::check::wfcheck::check_mod_type_wf
  36:     0x7fb329f779a1 - rustc_query_system[91a2545c0f12e962]::query::plumbing::try_execute_query::<rustc_query_impl[c17f0eee1516a7cd]::queries::check_mod_type_wf, rustc_query_impl[c17f0eee1516a7cd]::plumbing::QueryCtxt>
  37:     0x7fb329f773ad - <rustc_query_impl[c17f0eee1516a7cd]::Queries as rustc_middle[f0169fe793b61df1]::ty::query::QueryEngine>::check_mod_type_wf
  38:     0x7fb328dff588 - rustc_data_structures[6bf8f914372919d6]::sync::par_for_each_in::<&[rustc_hir[3fb8fe55df620ea3]::hir_id::OwnerId], <rustc_middle[f0169fe793b61df1]::hir::map::Map>::par_for_each_module<rustc_hir_analysis[154c1a05a8643cc4]::check_crate::{closure#5}::{closure#0}::{closure#0}>::{closure#0}>
  39:     0x7fb328dff373 - <rustc_session[a4ebe106e65405ac]::session::Session>::track_errors::<rustc_hir_analysis[154c1a05a8643cc4]::check_crate::{closure#5}, ()>
  40:     0x7fb328dff09a - rustc_hir_analysis[154c1a05a8643cc4]::check_crate
  41:     0x7fb328dfed3b - rustc_interface[aa88283fbb917e58]::passes::analysis
  42:     0x7fb32a1243fe - rustc_query_system[91a2545c0f12e962]::query::plumbing::try_execute_query::<rustc_query_impl[c17f0eee1516a7cd]::queries::analysis, rustc_query_impl[c17f0eee1516a7cd]::plumbing::QueryCtxt>
  43:     0x7fb32a3a179a - <rustc_query_impl[c17f0eee1516a7cd]::Queries as rustc_middle[f0169fe793b61df1]::ty::query::QueryEngine>::analysis
  44:     0x7fb329c24163 - <rustc_interface[aa88283fbb917e58]::passes::QueryContext>::enter::<rustc_driver[37eb5d1b4ab0972a]::run_compiler::{closure#1}::{closure#2}::{closure#2}, core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>>
  45:     0x7fb329c20693 - <rustc_interface[aa88283fbb917e58]::interface::Compiler>::enter::<rustc_driver[37eb5d1b4ab0972a]::run_compiler::{closure#1}::{closure#2}, core[bb4875f5a2cb5848]::result::Result<core[bb4875f5a2cb5848]::option::Option<rustc_interface[aa88283fbb917e58]::queries::Linker>, rustc_errors[385c082a2444c46]::ErrorGuaranteed>>
  46:     0x7fb329c1b678 - rustc_span[4c3f4c74ffe41368]::with_source_map::<core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>, rustc_interface[aa88283fbb917e58]::interface::run_compiler<core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>, rustc_driver[37eb5d1b4ab0972a]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  47:     0x7fb329c1b165 - <scoped_tls[775b62078ed86023]::ScopedKey<rustc_span[4c3f4c74ffe41368]::SessionGlobals>>::set::<rustc_interface[aa88283fbb917e58]::interface::run_compiler<core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>, rustc_driver[37eb5d1b4ab0972a]::run_compiler::{closure#1}>::{closure#0}, core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>>
  48:     0x7fb329c1a752 - std[d0bfc7d2f365d785]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[aa88283fbb917e58]::util::run_in_thread_pool_with_globals<rustc_interface[aa88283fbb917e58]::interface::run_compiler<core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>, rustc_driver[37eb5d1b4ab0972a]::run_compiler::{closure#1}>::{closure#0}, core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>>
  49:     0x7fb32a2a863a - <<std[d0bfc7d2f365d785]::thread::Builder>::spawn_unchecked_<rustc_interface[aa88283fbb917e58]::util::run_in_thread_pool_with_globals<rustc_interface[aa88283fbb917e58]::interface::run_compiler<core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>, rustc_driver[37eb5d1b4ab0972a]::run_compiler::{closure#1}>::{closure#0}, core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bb4875f5a2cb5848]::result::Result<(), rustc_errors[385c082a2444c46]::ErrorGuaranteed>>::{closure#1} as core[bb4875f5a2cb5848]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  50:     0x7fb3276d3a43 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h21ad39807731e3a4
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/alloc/src/boxed.rs:1988:9
  51:     0x7fb3276d3a43 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd46fbc14280dbb64
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/alloc/src/boxed.rs:1988:9
  52:     0x7fb3276d3a43 - std::sys::unix::thread::Thread::new::thread_start::h25ae217bcd9d33ca
                               at /rustc/c7572670a1302f5c7e245d069200e22da9df0316/library/std/src/sys/unix/thread.rs:108:17
  53:     0x7fb327597609 - start_thread
  54:     0x7fb3274ba133 - clone
  55:                0x0 - <unknown>

note: 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: rustc 1.68.0-nightly (c7572670a 2023-01-03) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [check_well_formed] checking that `<impl at src/lib.rs:11:1: 11:14>` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
@compiler-errors compiler-errors 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. F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Jan 4, 2023
@peter-lyons-kehl
Copy link
Contributor

peter-lyons-kehl commented Jan 6, 2023

Thank you Michael for minimizing this. It would have taken me more than a week...

It's not just impl SomeTrait for StructWithBoundedDefaultConstGeneric {...} that triggers this ICE. A similar error shows up when using type StructWithNoConstGeneric = StructWithBoundedDefaultConstGeneric<DEFAULT_VALUE_SAME_AS_IN_THAT_STRUCT_DEFINITION> (in a hope of finding a workaround):

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

const DEFAULT: u32 = 1;

struct CoV<const U: usize = DEFAULT>
where
    [(); U]:;

type V= CoV<DEFAULT>;

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=584689c4095f30a3655f596febc9ef56

I understand that, at least for now, this is a low priority (I hope it will rise up once I complete a CoAllocator MVP and have benchmarks). The only workaround that I see possible is to replace all occurrences of impl SomeTrait for StructWithBoundedDefaultConstGeneric {...} with impl SomeTrait for StructWithBoundedDefaultConstGeneric<DEFAULT_VALUE_SAME_AS_IN_THAT_STRUCT_DEFINITION> {...}. Any other workarounds, please?

@peter-lyons-kehl
Copy link
Contributor

peter-lyons-kehl commented Jan 6, 2023

  1. Oh oh. This (or similar) ICE happens even without any usage of the struct at all (no impl at all - not even an empty impl V {}, no type alias...):
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

const DEFAULT: u32 = 1;

struct CoV<const U: usize = DEFAULT>
where
    [(); U]:;

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=02291bab8ee053d05db0bfbfa57fbe67

Please double-check the ICE error message if it should be treated separately, or whether it would be likely to be fixable together with the two ICE examples listed above.

  1. Interim good news: This only happens when using an (existing) defined constant as the default value for the struct const generic parameter. If using a hard-coded value instead, it compiles well:
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

#[allow(dead_code)]
struct CoV<const U: usize = 1>
where
    [(); U]:;

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=26a2846ba3c2ea5ca81aaa4de6c3c910
= A good enough interim workaround for CoAlloc MVP.

And the original example (first one minimized in this issue) builds well with a hard-coded constant value, too:

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

struct V<const U: usize = 1>
where
    [(); U]:;

trait Tr {}

impl Tr for V {}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=ed7cc0144faf6ce64c2a8bb89428da79

  1. Back to the problem at hand: Calling a (const) function from the expression used as the default value fails, too:
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

const fn v_default() -> usize {
    1
}

struct V<const U: usize = {v_default()}>
where
    [(); U]:;

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=6df6a97016b1de1c4042f2a67382f1e5

Other failing variations:

  • const function-based expression for the const generic default value: struct V<const U: usize = {v_default() + 1}> ...
  • const function implemented for another struct:
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

struct Def {}
impl Def {
    const fn v_default() -> usize {
        1
    }
}

struct V<const U: usize = {Def::v_default()}>
where
    [(); U]:;

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=5afa13e7682309fbab62fca1012b4ab8

  • using cfg!(...) with a (hypothetical) target config field (failing, too):
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

struct V<const U: usize = {if cfg!(coop_alloc) {1} else {2}}>
where
    [(); U]:;

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=971190f4162846600db09b2f4282f754

  • even using a simple if ... {...} else {...} makes it fail, too:
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

struct V<const U: usize = {if true {1} else {2}}>
where
    [(); U]:;

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=c5387bdd403a74aed51935462bc94d63

  1. Good news again: I've found a way to centralize the default value (so that it can be shared by several structs or enums), and hopefully it helps you (the compiler expert) to narrow down this ICE even closer. The code does build when using a macro call for the default value:
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

macro_rules! co_vec_default {
    () => {
        1
    }
}

struct V<const U: usize = {co_vec_default!()}>
where
    [(); U]:;

trait Tr {}

impl Tr for V {}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=4b529f246dfb1aeb38380425487ad219

  1. Side note for anyone using the macro workaround: Calling a macro in the impl ... for V<{co_vec_default!()}> generates a false positive unused_braces warning: False positive unused_braces when calling a macro #106545.

Thank you for your help.
Thank you in advance for any progress.

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 17, 2023

closing in favor of #106994

peter-lyons-kehl added a commit to coop-rs/rust that referenced this issue Feb 15, 2023
peter-lyons-kehl added a commit to coop-rs/rust that referenced this issue Feb 19, 2023
peter-lyons-kehl added a commit to coop-rs/rust that referenced this issue Feb 20, 2023
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

4 participants