Skip to content

compiler crash caused by using feature(generic_const_exprs) #114212

Closed as not planned
@Retamogordo

Description

@Retamogordo

This a minimized code that causes the compiler to crash. While the example itself doesn't need the generic_const_exprs feature, the original library uses it and even compiles, but a binary that depends on the library and itself does not include generic_const_exprs feature, causes the exactly same internal compiler error

Code

#![feature(generic_const_exprs)]

use core::marker::PhantomData;

pub const DEFAULT_MAX_INPUT_LEN: usize = 256;

pub trait FooTrait {}

pub struct Foo<const MAX_INPUT_LEN: usize>;

impl<const MAX_INPUT_LEN: usize> FooTrait for Foo<MAX_INPUT_LEN> {}

pub struct Bar<
    const MAX_INPUT_LEN: usize = DEFAULT_MAX_INPUT_LEN,
    PB = Foo<MAX_INPUT_LEN>,
> 
where
    PB: FooTrait,
{
    _pb: PhantomData<PB>,
}

impl<const MAX_INPUT_LEN: usize, PB> Bar<MAX_INPUT_LEN, PB>
where
    PB: FooTrait,
{
    pub fn new() -> Self {
        Self {
            _pb: PhantomData,
        }
    }
}

Meta

rustc 1.70.0-nightly (22f247c6f 2023-03-13)
binary: rustc
commit-hash: 22f247c6f3ed388cb702d01c2ff27da658a8b353
commit-date: 2023-03-13
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7

Error output

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> for more information
  = note: `#[warn(incomplete_features)]` on by default

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:896:9: type parameter `PB/#1` (PB/1) out of range when substituting, substs=[]

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/compiler/rustc_errors/src/lib.rs:1644:9
stack backtrace:
   0:     0x7f88f9ad751a - std::backtrace_rs::backtrace::libunwind::trace::h1ac6254167c780d9
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f88f9ad751a - std::backtrace_rs::backtrace::trace_unsynchronized::hec2af85915e24f36
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f88f9ad751a - std::sys_common::backtrace::_print_fmt::h58a4e3535fcce206
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f88f9ad751a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5107e13758b8321c
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f88f9b3ac5e - core::fmt::write::h2e851dc027730d81
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/core/src/fmt/mod.rs:1232:17
   5:     0x7f88f9aca375 - std::io::Write::write_fmt::hca00074de9f85084
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/std/src/io/mod.rs:1684:15
   6:     0x7f88f9ad72e5 - std::sys_common::backtrace::_print::h870053c845cddf24
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f88f9ad72e5 - std::sys_common::backtrace::print::hb56add862f96c5fd
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f88f9ada05f - std::panicking::default_hook::{{closure}}::h636d4ba3ff8fdc46
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/std/src/panicking.rs:271:22
   9:     0x7f88f9ad9d9b - std::panicking::default_hook::hf29b58145ee6e43c
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/std/src/panicking.rs:290:9
  10:     0x7f88fcdc90c5 - <rustc_driver_impl[74350ec99973fded]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[2011dc7817943e09]::ops::function::FnOnce<(&core[2011dc7817943e09]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7f88f9ada89d - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h7342d57f33f6634f
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/alloc/src/boxed.rs:2002:9
  12:     0x7f88f9ada89d - std::panicking::rust_panic_with_hook::hbf9ef936d990c16f
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/std/src/panicking.rs:696:13
  13:     0x7f88fd3335b1 - std[1337fb43929788f1]::panicking::begin_panic::<rustc_errors[9dbe0d28acf3471b]::ExplicitBug>::{closure#0}
  14:     0x7f88fd32ea36 - std[1337fb43929788f1]::sys_common::backtrace::__rust_end_short_backtrace::<std[1337fb43929788f1]::panicking::begin_panic<rustc_errors[9dbe0d28acf3471b]::ExplicitBug>::{closure#0}, !>
  15:     0x7f88fd3b3e86 - std[1337fb43929788f1]::panicking::begin_panic::<rustc_errors[9dbe0d28acf3471b]::ExplicitBug>
  16:     0x7f88fd37ffe6 - std[1337fb43929788f1]::panic::panic_any::<rustc_errors[9dbe0d28acf3471b]::ExplicitBug>
  17:     0x7f88fd37c866 - <rustc_errors[9dbe0d28acf3471b]::HandlerInner>::bug::<&alloc[b7ae3602ac956de8]::string::String>
  18:     0x7f88fd37c530 - <rustc_errors[9dbe0d28acf3471b]::Handler>::bug::<&alloc[b7ae3602ac956de8]::string::String>
  19:     0x7f88fd36895b - rustc_middle[eaae5d2a0b8f0144]::util::bug::opt_span_bug_fmt::<rustc_span[18b84908941c7cdf]::span_encoding::Span>::{closure#0}
  20:     0x7f88fd3673ba - rustc_middle[eaae5d2a0b8f0144]::ty::context::tls::with_opt::<rustc_middle[eaae5d2a0b8f0144]::util::bug::opt_span_bug_fmt<rustc_span[18b84908941c7cdf]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f88fd367386 - rustc_middle[eaae5d2a0b8f0144]::ty::context::tls::with_context_opt::<rustc_middle[eaae5d2a0b8f0144]::ty::context::tls::with_opt<rustc_middle[eaae5d2a0b8f0144]::util::bug::opt_span_bug_fmt<rustc_span[18b84908941c7cdf]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f88fd3688a6 - rustc_middle[eaae5d2a0b8f0144]::util::bug::opt_span_bug_fmt::<rustc_span[18b84908941c7cdf]::span_encoding::Span>
  23:     0x7f88fb4a25c3 - rustc_middle[eaae5d2a0b8f0144]::util::bug::bug_fmt
  24:     0x7f88fd33d6ae - <rustc_middle[eaae5d2a0b8f0144]::ty::subst::SubstFolder>::type_param_out_of_range
  25:     0x7f88faddc725 - <rustc_middle[eaae5d2a0b8f0144]::ty::subst::SubstFolder as rustc_type_ir[65f3a8acf733f7d2]::fold::FallibleTypeFolder<rustc_middle[eaae5d2a0b8f0144]::ty::context::TyCtxt>>::try_fold_ty
  26:     0x7f88faf09184 - <rustc_middle[eaae5d2a0b8f0144]::ty::generics::GenericPredicates>::instantiate_into
  27:     0x7f88fb4aec05 - <rustc_trait_selection[88fe5da1728944e3]::traits::wf::WfPredicates>::nominal_obligations_inner
  28:     0x7f88fb47b284 - <rustc_trait_selection[88fe5da1728944e3]::traits::wf::WfPredicates>::compute
  29:     0x7f88fb471901 - rustc_trait_selection[88fe5da1728944e3]::traits::wf::obligations
  30:     0x7f88fb45871c - <rustc_trait_selection[88fe5da1728944e3]::traits::fulfill::FulfillProcessor as rustc_data_structures[75b47a18491287a9]::obligation_forest::ObligationProcessor>::process_obligation
  31:     0x7f88fb455b44 - <rustc_data_structures[75b47a18491287a9]::obligation_forest::ObligationForest<rustc_trait_selection[88fe5da1728944e3]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[88fe5da1728944e3]::traits::fulfill::FulfillProcessor>
  32:     0x7f88fb993e70 - <rustc_trait_selection[88fe5da1728944e3]::traits::engine::ObligationCtxt>::select_all_or_error
  33:     0x7f88fbc93602 - rustc_hir_analysis[80836a89449caedf]::check::wfcheck::check_type_defn
  34:     0x7f88fbc71105 - rustc_hir_analysis[80836a89449caedf]::check::wfcheck::check_well_formed
  35:     0x7f88fb239d14 - rustc_query_system[f881c7f40ee7dcf0]::query::plumbing::try_execute_query::<rustc_query_impl[eb95ff51c492efdd]::queries::check_well_formed, rustc_query_impl[eb95ff51c492efdd]::plumbing::QueryCtxt>
  36:     0x7f88fc5aa256 - rustc_query_system[f881c7f40ee7dcf0]::query::plumbing::force_query::<rustc_query_impl[eb95ff51c492efdd]::queries::check_well_formed, rustc_query_impl[eb95ff51c492efdd]::plumbing::QueryCtxt>
  37:     0x7f88fc5aa10c - <rustc_query_impl[eb95ff51c492efdd]::plumbing::query_callback<rustc_query_impl[eb95ff51c492efdd]::queries::check_well_formed>::{closure#0} as core[2011dc7817943e09]::ops::function::FnOnce<(rustc_middle[eaae5d2a0b8f0144]::ty::context::TyCtxt, rustc_query_system[f881c7f40ee7dcf0]::dep_graph::dep_node::DepNode<rustc_middle[eaae5d2a0b8f0144]::dep_graph::dep_node::DepKind>)>>::call_once
  38:     0x7f88faf02bcc - <rustc_query_system[f881c7f40ee7dcf0]::dep_graph::graph::DepGraphData<rustc_middle[eaae5d2a0b8f0144]::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl[eb95ff51c492efdd]::plumbing::QueryCtxt>
  39:     0x7f88fbc46c38 - <rustc_query_system[f881c7f40ee7dcf0]::dep_graph::graph::DepGraph<rustc_middle[eaae5d2a0b8f0144]::dep_graph::dep_node::DepKind>>::try_mark_green::<rustc_query_impl[eb95ff51c492efdd]::plumbing::QueryCtxt>
  40:     0x7f88fc4083a2 - rustc_query_system[f881c7f40ee7dcf0]::query::plumbing::ensure_must_run::<rustc_query_impl[eb95ff51c492efdd]::queries::check_mod_type_wf, rustc_query_impl[eb95ff51c492efdd]::plumbing::QueryCtxt>
  41:     0x7f88fc4081d4 - <rustc_query_impl[eb95ff51c492efdd]::Queries as rustc_middle[eaae5d2a0b8f0144]::ty::query::QueryEngine>::check_mod_type_wf
  42:     0x7f88fb1b9128 - rustc_data_structures[75b47a18491287a9]::sync::par_for_each_in::<&[rustc_hir[ca07edd3831bb6e2]::hir_id::OwnerId], <rustc_middle[eaae5d2a0b8f0144]::hir::map::Map>::par_for_each_module<rustc_hir_analysis[80836a89449caedf]::check_crate::{closure#5}::{closure#0}::{closure#0}>::{closure#0}>
  43:     0x7f88fb1b8fb0 - <rustc_session[a360c2d099171c08]::session::Session>::track_errors::<rustc_hir_analysis[80836a89449caedf]::check_crate::{closure#5}, ()>
  44:     0x7f88fb1b61e0 - rustc_hir_analysis[80836a89449caedf]::check_crate
  45:     0x7f88fb1ac1b2 - rustc_interface[ceda1fd77ec39e1b]::passes::analysis
  46:     0x7f88fc5e7c6d - rustc_query_system[f881c7f40ee7dcf0]::query::plumbing::try_execute_query::<rustc_query_impl[eb95ff51c492efdd]::queries::analysis, rustc_query_impl[eb95ff51c492efdd]::plumbing::QueryCtxt>
  47:     0x7f88fc5e7740 - <rustc_query_impl[eb95ff51c492efdd]::Queries as rustc_middle[eaae5d2a0b8f0144]::ty::query::QueryEngine>::analysis
  48:     0x7f88fc410789 - <rustc_middle[eaae5d2a0b8f0144]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[74350ec99973fded]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[2011dc7817943e09]::result::Result<(), rustc_span[18b84908941c7cdf]::ErrorGuaranteed>>
  49:     0x7f88fbffff08 - rustc_span[18b84908941c7cdf]::with_source_map::<core[2011dc7817943e09]::result::Result<(), rustc_span[18b84908941c7cdf]::ErrorGuaranteed>, rustc_interface[ceda1fd77ec39e1b]::interface::run_compiler<core[2011dc7817943e09]::result::Result<(), rustc_span[18b84908941c7cdf]::ErrorGuaranteed>, rustc_driver_impl[74350ec99973fded]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  50:     0x7f88fbff716c - std[1337fb43929788f1]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[ceda1fd77ec39e1b]::util::run_in_thread_pool_with_globals<rustc_interface[ceda1fd77ec39e1b]::interface::run_compiler<core[2011dc7817943e09]::result::Result<(), rustc_span[18b84908941c7cdf]::ErrorGuaranteed>, rustc_driver_impl[74350ec99973fded]::run_compiler::{closure#1}>::{closure#0}, core[2011dc7817943e09]::result::Result<(), rustc_span[18b84908941c7cdf]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[2011dc7817943e09]::result::Result<(), rustc_span[18b84908941c7cdf]::ErrorGuaranteed>>
  51:     0x7f88fbff6b9a - <<std[1337fb43929788f1]::thread::Builder>::spawn_unchecked_<rustc_interface[ceda1fd77ec39e1b]::util::run_in_thread_pool_with_globals<rustc_interface[ceda1fd77ec39e1b]::interface::run_compiler<core[2011dc7817943e09]::result::Result<(), rustc_span[18b84908941c7cdf]::ErrorGuaranteed>, rustc_driver_impl[74350ec99973fded]::run_compiler::{closure#1}>::{closure#0}, core[2011dc7817943e09]::result::Result<(), rustc_span[18b84908941c7cdf]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[2011dc7817943e09]::result::Result<(), rustc_span[18b84908941c7cdf]::ErrorGuaranteed>>::{closure#1} as core[2011dc7817943e09]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  52:     0x7f88f9ae4793 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7e0474dd3b8659fa
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/alloc/src/boxed.rs:1988:9
  53:     0x7f88f9ae4793 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::heb8c41cf543a5c11
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/alloc/src/boxed.rs:1988:9
  54:     0x7f88f9ae4793 - std::sys::unix::thread::Thread::new::thread_start::hc791abe67253fe06
                               at /rustc/22f247c6f3ed388cb702d01c2ff27da658a8b353/library/std/src/sys/unix/thread.rs:108:17
  55:     0x7f88f9991609 - start_thread
                               at /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477:8
  56:     0x7f88f98b4133 - clone
                               at /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  57:                0x0 - <unknown>

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.70.0-nightly (22f247c6f 2023-03-13) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
#0 [check_well_formed] checking that `Bar` is well-formed
#1 [analysis] running analysis passes on this crate
end of query stack
encountered while trying to mark dependency green: check_well_formed(3cb10481615348b4-30cdf74b78880f65)
encountered while trying to mark dependency green: check_mod_type_wf(3cb10481615348b4-e797e994292788bb)
warning: `compiler-failure` (lib) generated 1 warning
error: could not compile `compiler-failure` (lib); 1 warning emitted
Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-incomplete-featuresThis issue requires the use of incomplete features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions