Closed
Description
When establishing default generic members dependent on the value of another generic, the compiler will hint towards the following:
unconstrained generic constant
try adding a `where` bound using this expression: `where [(); { X + Y }]:`
After trying this the compiler seems to be fine but after running cargo build
there is an internal compiler error.
Code
#![allow(incomplete_features)]
#![feature(generic_const_exprs, generic_arg_infer)]
pub trait Example<const X: usize, const Y: usize, const Z: usize = { X + Y }>
where
[(); X + Y]:,
{}
impl<const X: usize, const Y: usize> Example<X, Y> for Value {}
pub struct Value;
fn main() {}
In the case of this error, the following is the unconstrained generic:
const Z: usize = { X + Y }
If we replace { X + Y }
with a static integer, such as 4
, then everything works fine. I'm assuming the error is originating from the generic_const_exprs
feature because of this.
Meta
rustc --version --verbose
:
rustc 1.71.0-nightly (2f6bc5d25 2023-05-09)
binary: rustc
commit-hash: 2f6bc5d259e7ab25ddfdd33de53b892770218918
commit-date: 2023-05-09
host: x86_64-pc-windows-msvc
release: 1.71.0-nightly
LLVM version: 16.0.2
Error output
error: internal compiler error: compiler\rustc_middle\src\ty\subst.rs:933:9: const parameter `Z/#3` (Const { ty: usize, kind: Param(Z/#3) }/3) out of range when substituting substs=[Value, Const { ty: usize, kind: Param(X/#0) }, Const { ty: usize, kind: Param(Y/#1) }]
Backtrace
error: internal compiler error: compiler\rustc_middle\src\ty\subst.rs:933:9: const parameter `Z/#3` (Const { ty: usize, kind: Param(Z/#3) }/3) out of range when substituting substs=[Value, Const { ty: usize, kind: Param(X/#0) }, Const { ty: usize, kind: Param(Y/#1) }]
thread 'rustc' panicked at 'Box<dyn Any>', /rustc/2f6bc5d259e7ab25ddfdd33de53b892770218918\compiler\rustc_errors\src\lib.rs:1650:9
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
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.71.0-nightly (2f6bc5d25 2023-05-09) running on x86_64-pc-windows-msvc
note: compiler flags: --crate-type bin -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 `<impl at src\main.rs:9:1: 9:61>` 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
error: could not compile `t1` (bin "t1")
Full Backtrace
error: internal compiler error: compiler\rustc_middle\src\ty\subst.rs:933:9: const parameter `Z/#3` (Const { ty: usize, kind: Param(Z/#3) }/3) out of range when substituting substs=[Value, Const { ty: usize, kind: Param(X/#0) }, Const { ty: usize, kind: Param(Y/#1) }]
thread 'rustc' panicked at 'Box<dyn Any>', /rustc/2f6bc5d259e7ab25ddfdd33de53b892770218918\compiler\rustc_errors\src\lib.rs:1650:9
stack backtrace:
0: 0x7ff9747b614c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h6a49e06e6dee2bf9
1: 0x7ff9747eef7b - core::fmt::write::he8d8f68a61258e76
2: 0x7ff9747ab819 - <std::io::IoSlice as core::fmt::Debug>::fmt::hc7a877c678f27ace
3: 0x7ff9747b5efb - std::sys::common::alloc::realloc_fallback::hb0c4c746d16999f4
4: 0x7ff9747b9729 - std::panicking::default_hook::he9785754479d3c09
5: 0x7ff9747b93df - std::panicking::default_hook::he9785754479d3c09
6: 0x7ff943e4e716 - rustc_driver_impl[33202727405cf2b1]::install_ice_hook
7: 0x7ff9747b9e2b - std::panicking::rust_panic_with_hook::ha9d065be1dad797b
8: 0x7ff946363773 - <rustc_middle[62881603dcf8d3f1]::ty::fast_reject::DeepRejectCtxt as core[6d1b28d878a231cd]::fmt::Debug>::fmt
9: 0x7ff9463611b9 - <rustc_middle[62881603dcf8d3f1]::ty::fast_reject::DeepRejectCtxt as core[6d1b28d878a231cd]::fmt::Debug>::fmt
10: 0x7ff946360f19 - <rustc_middle[62881603dcf8d3f1]::ty::fast_reject::DeepRejectCtxt as core[6d1b28d878a231cd]::fmt::Debug>::fmt
11: 0x7ff94635a0a0 - <rustc_middle[62881603dcf8d3f1]::ty::fast_reject::DeepRejectCtxt as core[6d1b28d878a231cd]::fmt::Debug>::fmt
12: 0x7ff946359c5c - <rustc_middle[62881603dcf8d3f1]::ty::fast_reject::DeepRejectCtxt as core[6d1b28d878a231cd]::fmt::Debug>::fmt
13: 0x7ff946333b6d - rustc_middle[62881603dcf8d3f1]::util::bug::bug_fmt
14: 0x7ff94633312d - <rustc_middle[62881603dcf8d3f1]::ty::consts::valtree::ValTree>::try_to_raw_bytes
15: 0x7ff9463330ef - <rustc_middle[62881603dcf8d3f1]::ty::consts::valtree::ValTree>::try_to_raw_bytes
16: 0x7ff946333a5f - rustc_middle[62881603dcf8d3f1]::util::bug::bug_fmt
17: 0x7ff94636bbf5 - <rustc_middle[62881603dcf8d3f1]::ty::subst::GenericArg as rustc_middle[62881603dcf8d3f1]::ty::context::Lift>::lift_to_tcx
18: 0x7ff943d47553 - <rustc_middle[62881603dcf8d3f1]::ty::subst::GenericArg>::expect_ty
19: 0x7ff943d6ff23 - <rustc_middle[62881603dcf8d3f1]::ty::list::List<rustc_middle[62881603dcf8d3f1]::ty::subst::GenericArg>>::truncate_to
20: 0x7ff943d4cdc6 - <rustc_middle[62881603dcf8d3f1]::ty::rvalue_scopes::RvalueScopes>::temporary_scope
21: 0x7ff943d4732c - <rustc_middle[62881603dcf8d3f1]::ty::subst::GenericArg>::expect_ty
22: 0x7ff943dae356 - <rustc_middle[62881603dcf8d3f1]::ty::context::TyCtxt>::instance_mir
23: 0x7ff943d041af - <rustc_middle[62881603dcf8d3f1]::ty::query::TyCtxtEnsure>::const_eval_poly
24: 0x7ff943cfa483 - <rustc_middle[62881603dcf8d3f1]::ty::generics::GenericPredicates>::instantiate
25: 0x7ff943c2b1eb - rustc_trait_selection[74703593c0cab2a9]::traits::wf::predicate_obligations
26: 0x7ff943c28d32 - rustc_trait_selection[74703593c0cab2a9]::traits::wf::predicate_obligations
27: 0x7ff943b5aac8 - <rustc_trait_selection[74703593c0cab2a9]::traits::fulfill::FulfillProcessor as rustc_data_structures[2f16d3680bbdb9f7]::obligation_forest::ObligationProcessor>::process_obligation
28: 0x7ff943bf4550 - rustc_trait_selection[74703593c0cab2a9]::traits::project::normalize_projection_type
29: 0x7ff943bfe312 - <rustc_trait_selection[74703593c0cab2a9]::traits::engine::ObligationCtxt>::select_all_or_error
30: 0x7ff94311d6e2 - <rustc_infer[776602ba86f8fd70]::infer::InferCtxt as rustc_hir_analysis[c8cf2ee9fbb508a6]::astconv::InferCtxtExt>::fresh_item_substs
31: 0x7ff9420a71e8 - <rustc_query_impl[32ff81daef66415]::queries::exported_symbols as rustc_query_system[3f75387262d59d80]::query::config::QueryConfig<rustc_query_impl[32ff81daef66415]::plumbing::QueryCtxt>>::execute_query
32: 0x7ff9437ed8ad - <rustc_query_impl[32ff81daef66415]::queries::lookup_deprecation_entry as rustc_query_system[3f75387262d59d80]::query::config::QueryConfig<rustc_query_impl[32ff81daef66415]::plumbing::QueryCtxt>>::execute_query
33: 0x7ff9437242ae - rustc_query_impl[32ff81daef66415]::query_callbacks
34: 0x7ff9431063d5 - rustc_hir_analysis[c8cf2ee9fbb508a6]::check::check::check_abi
35: 0x7ff941de756b - <rustc_hir_analysis[c8cf2ee9fbb508a6]::check::wfcheck::ImplTraitInTraitFinder as rustc_type_ir[25b48e22f8e5c9fa]::visit::TypeVisitor<rustc_middle[62881603dcf8d3f1]::ty::context::TyCtxt>>::visit_ty
36: 0x7ff9420a71e8 - <rustc_query_impl[32ff81daef66415]::queries::exported_symbols as rustc_query_system[3f75387262d59d80]::query::config::QueryConfig<rustc_query_impl[32ff81daef66415]::plumbing::QueryCtxt>>::execute_query
37: 0x7ff9420fda9e - <rustc_query_impl[32ff81daef66415]::queries::exported_symbols as rustc_query_system[3f75387262d59d80]::query::config::QueryConfig<rustc_query_impl[32ff81daef66415]::plumbing::QueryCtxt>>::execute_query
38: 0x7ff94203f548 - rustc_query_impl[32ff81daef66415]::query_system_fns
39: 0x7ff941dda3a8 - <rustc_hir_analysis[c8cf2ee9fbb508a6]::autoderef::Autoderef>::silence_errors
40: 0x7ff9430b37e0 - rustc_hir_analysis[c8cf2ee9fbb508a6]::check_crate
41: 0x7ff94166a018 - rustc_interface[96f19ec40f526bfb]::passes::analysis
42: 0x7ff9421930ba - <rustc_query_impl[32ff81daef66415]::queries::exported_symbols as rustc_query_system[3f75387262d59d80]::query::config::QueryConfig<rustc_query_impl[32ff81daef66415]::plumbing::QueryCtxt>>::execute_query
43: 0x7ff9420a7924 - <rustc_query_impl[32ff81daef66415]::queries::exported_symbols as rustc_query_system[3f75387262d59d80]::query::config::QueryConfig<rustc_query_impl[32ff81daef66415]::plumbing::QueryCtxt>>::execute_query
44: 0x7ff942185e59 - <rustc_query_impl[32ff81daef66415]::queries::exported_symbols as rustc_query_system[3f75387262d59d80]::query::config::QueryConfig<rustc_query_impl[32ff81daef66415]::plumbing::QueryCtxt>>::execute_query
45: 0x7ff94203bda1 - rustc_query_impl[32ff81daef66415]::query_system_fns
46: 0x7ff94163c8b9 - <rustc_middle[62881603dcf8d3f1]::ty::SymbolName as core[6d1b28d878a231cd]::fmt::Debug>::fmt
47: 0x7ff94161a088 - rustc_driver_impl[33202727405cf2b1]::args::arg_expand_all
48: 0x7ff941638e53 - rustc_driver_impl[33202727405cf2b1]::args::arg_expand_all
49: 0x7ff94163a2a6 - rustc_driver_impl[33202727405cf2b1]::args::arg_expand_all
50: 0x7ff9747cd19c - std::sys::windows::thread::Thread::new::h703068e96e3b4903
51: 0x7ff9c5427604 - BaseThreadInitThunk
52: 0x7ff9c6c426a1 - RtlUserThreadStart
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.71.0-nightly (2f6bc5d25 2023-05-09) running on x86_64-pc-windows-msvc
note: compiler flags: --crate-type bin -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 `<impl at src\main.rs:9:1: 9:61>` 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
error: could not compile `t1` (bin "t1")
Metadata
Metadata
Assignees
Labels
Category: This is a bug.`#![feature(generic_const_exprs)]`Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Status: This bug is tracked inside the repo by a `known-bug` test.Relevant to the compiler team, which will review and decide on the PR/issue.This issue requires the use of incomplete features.This issue requires a nightly compiler in some way.