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: gce: unable to construct a constant value for the unevaluated constant UnevaluatedConst {..} #118545

Closed
matthiaskrgr opened this issue Dec 2, 2023 · 2 comments · Fixed by #132927
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-incomplete-features This issue requires the use of incomplete features. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

struct Checked<const F: fn(usize) -> bool>;

fn not_one(val: usize) -> bool {
    val != 1
}
const _: Checked<not_one> = Checked::<not_one>;

#![feature(generic_const_exprs)]

original:

struct Checked<const F: fn(usize) -> bool>;
//~^ ERROR function pointers as const generic parameters is forbidden
fn not_one(val: usize) -> bool { val != 1 }
const _: Checked<not_one> = Checked::<not_one>;
fn main() {}

Version information

rustc 1.76.0-nightly (4e3dc976e 2023-12-02)
binary: rustc
commit-hash: 4e3dc976e7876f59373ddc8ac176fe130636bcd1
commit-date: 2023-12-02
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.5

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(generic_const_exprs)

Program output

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

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.gHur7OqFWv0M/rustc_testrunner_tmpdir_reporting.xiUdgEkFncd9/mvce.rs:6:48
  |
6 | const _: Checked<not_one> = Checked::<not_one>;
  |                                                ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.gHur7OqFWv0M/rustc_testrunner_tmpdir_reporting.xiUdgEkFncd9/mvce.rs`

error: using function pointers as const generic parameters is forbidden
 --> /tmp/icemaker_global_tempdir.gHur7OqFWv0M/rustc_testrunner_tmpdir_reporting.xiUdgEkFncd9/mvce.rs:1:25
  |
1 | struct Checked<const F: fn(usize) -> bool>;
  |                         ^^^^^^^^^^^^^^^^^
  |
  = note: the only supported types are integers, `bool` and `char`

error: internal compiler error: compiler/rustc_infer/src/infer/mod.rs:1579:17: unable to construct a constant value for the unevaluated constant UnevaluatedConst { def: DefId(0:8 ~ mvce[7b0d]::_::{constant#0}), args: [] }
 --> /tmp/icemaker_global_tempdir.gHur7OqFWv0M/rustc_testrunner_tmpdir_reporting.xiUdgEkFncd9/mvce.rs:6:18
  |
6 | const _: Checked<not_one> = Checked::<not_one>;
  |                  ^^^^^^^

thread 'rustc' panicked at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/compiler/rustc_errors/src/lib.rs:995:33:
Box<dyn Any>
stack backtrace:
   0:     0x7fda6dbd528c - std::backtrace_rs::backtrace::libunwind::trace::h6817338c94b27a3e
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fda6dbd528c - std::backtrace_rs::backtrace::trace_unsynchronized::h0c6d9d3798c92386
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fda6dbd528c - std::sys_common::backtrace::_print_fmt::h834bcd6a65d45603
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7fda6dbd528c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h632d407336012a57
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fda6dc282c0 - core::fmt::rt::Argument::fmt::h01e7093f49b63767
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/core/src/fmt/rt.rs:142:9
   5:     0x7fda6dc282c0 - core::fmt::write::h38701b4f0b2dfcb8
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/core/src/fmt/mod.rs:1120:17
   6:     0x7fda6dbc917f - std::io::Write::write_fmt::hb5f3f03cb3ca04d4
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/std/src/io/mod.rs:1810:15
   7:     0x7fda6dbd5074 - std::sys_common::backtrace::_print::hd3e5ed5a0b531af5
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fda6dbd5074 - std::sys_common::backtrace::print::hb9af834fe41953f4
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fda6dbd7d07 - std::panicking::default_hook::{{closure}}::h72d658988ab66f01
  10:     0x7fda6dbd7a6f - std::panicking::default_hook::h58213f9fd1d3009c
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/std/src/panicking.rs:292:9
  11:     0x7fda6a8f5cd0 - std[df2d6593d7194e63]::panicking::update_hook::<alloc[8a854d67183381ee]::boxed::Box<rustc_driver_impl[6cfe35843c87edd3]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fda6dbd8448 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h7fd395d777c5491c
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/alloc/src/boxed.rs:2021:9
  13:     0x7fda6dbd8448 - std::panicking::rust_panic_with_hook::h98c8112ef43197a0
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/std/src/panicking.rs:783:13
  14:     0x7fda6ab7e564 - std[df2d6593d7194e63]::panicking::begin_panic::<rustc_errors[1ca61f24e5e0d229]::ExplicitBug>::{closure#0}
  15:     0x7fda6ab68386 - std[df2d6593d7194e63]::sys_common::backtrace::__rust_end_short_backtrace::<std[df2d6593d7194e63]::panicking::begin_panic<rustc_errors[1ca61f24e5e0d229]::ExplicitBug>::{closure#0}, !>
  16:     0x7fda6ab61426 - std[df2d6593d7194e63]::panicking::begin_panic::<rustc_errors[1ca61f24e5e0d229]::ExplicitBug>
  17:     0x7fda6ab51dae - <rustc_errors[1ca61f24e5e0d229]::HandlerInner>::span_bug::<rustc_span[9dcec85a30c01535]::span_encoding::Span, alloc[8a854d67183381ee]::string::String>
  18:     0x7fda6ab51708 - <rustc_errors[1ca61f24e5e0d229]::Handler>::span_bug::<rustc_span[9dcec85a30c01535]::span_encoding::Span, alloc[8a854d67183381ee]::string::String>
  19:     0x7fda6ab7ea9b - rustc_middle[decbaea72911547]::util::bug::opt_span_bug_fmt::<rustc_span[9dcec85a30c01535]::span_encoding::Span>::{closure#0}
  20:     0x7fda6ab7eaca - rustc_middle[decbaea72911547]::ty::context::tls::with_opt::<rustc_middle[decbaea72911547]::util::bug::opt_span_bug_fmt<rustc_span[9dcec85a30c01535]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7fda6ab683c8 - rustc_middle[decbaea72911547]::ty::context::tls::with_context_opt::<rustc_middle[decbaea72911547]::ty::context::tls::with_opt<rustc_middle[decbaea72911547]::util::bug::opt_span_bug_fmt<rustc_span[9dcec85a30c01535]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7fda6ab65284 - rustc_middle[decbaea72911547]::util::bug::span_bug_fmt::<rustc_span[9dcec85a30c01535]::span_encoding::Span>
  23:     0x7fda6abdb209 - <rustc_infer[d655d61eba052e30]::infer::InferCtxt>::try_const_eval_resolve
  24:     0x7fda6b455819 - <rustc_trait_selection[34dffbdf25348a0a]::traits::fulfill::FulfillProcessor as rustc_data_structures[47340807f7653890]::obligation_forest::ObligationProcessor>::process_obligation::{closure#1}
  25:     0x7fda68d08123 - <rustc_trait_selection[34dffbdf25348a0a]::traits::fulfill::FulfillProcessor as rustc_data_structures[47340807f7653890]::obligation_forest::ObligationProcessor>::process_obligation
  26:     0x7fda6bc11b84 - <rustc_data_structures[47340807f7653890]::obligation_forest::ObligationForest<rustc_trait_selection[34dffbdf25348a0a]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[34dffbdf25348a0a]::traits::fulfill::FulfillProcessor>
  27:     0x7fda6c5a9184 - <rustc_hir_typeck[9593c8bda2de2b24]::fn_ctxt::FnCtxt>::type_inference_fallback
  28:     0x7fda6bf138ad - rustc_hir_typeck[9593c8bda2de2b24]::typeck
  29:     0x7fda6bf12c7d - rustc_query_impl[ff29417da00622fc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ff29417da00622fc]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[decbaea72911547]::query::erase::Erased<[u8; 8usize]>>
  30:     0x7fda6be50143 - rustc_query_system[9cd2f7f31604691c]::query::plumbing::try_execute_query::<rustc_query_impl[ff29417da00622fc]::DynamicConfig<rustc_query_system[9cd2f7f31604691c]::query::caches::VecCache<rustc_span[9dcec85a30c01535]::def_id::LocalDefId, rustc_middle[decbaea72911547]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[ff29417da00622fc]::plumbing::QueryCtxt, false>
  31:     0x7fda6be4fdd0 - rustc_query_impl[ff29417da00622fc]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7fda6c8d5570 - rustc_hir_analysis[da2a6e1063fa42ac]::check::check::check_mod_item_types
  33:     0x7fda6c8d4fb9 - rustc_query_impl[ff29417da00622fc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ff29417da00622fc]::query_impl::check_mod_item_types::dynamic_query::{closure#2}::{closure#0}, rustc_middle[decbaea72911547]::query::erase::Erased<[u8; 0usize]>>
  34:     0x7fda6c5f65bb - rustc_query_system[9cd2f7f31604691c]::query::plumbing::try_execute_query::<rustc_query_impl[ff29417da00622fc]::DynamicConfig<rustc_query_system[9cd2f7f31604691c]::query::caches::DefaultCache<rustc_span[9dcec85a30c01535]::def_id::LocalModDefId, rustc_middle[decbaea72911547]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[ff29417da00622fc]::plumbing::QueryCtxt, false>
  35:     0x7fda6c5f5f97 - rustc_query_impl[ff29417da00622fc]::query_impl::check_mod_item_types::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7fda6c624b23 - rustc_hir_analysis[da2a6e1063fa42ac]::check_crate
  37:     0x7fda6c782722 - rustc_interface[6c8aab51a4e81018]::passes::analysis
  38:     0x7fda6c78235d - rustc_query_impl[ff29417da00622fc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ff29417da00622fc]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[decbaea72911547]::query::erase::Erased<[u8; 1usize]>>
  39:     0x7fda6cb65e80 - rustc_query_system[9cd2f7f31604691c]::query::plumbing::try_execute_query::<rustc_query_impl[ff29417da00622fc]::DynamicConfig<rustc_query_system[9cd2f7f31604691c]::query::caches::SingleCache<rustc_middle[decbaea72911547]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[ff29417da00622fc]::plumbing::QueryCtxt, false>
  40:     0x7fda6cb65c87 - rustc_query_impl[ff29417da00622fc]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7fda6cb74552 - rustc_interface[6c8aab51a4e81018]::interface::run_compiler::<core[50500588ec9d0052]::result::Result<(), rustc_span[9dcec85a30c01535]::ErrorGuaranteed>, rustc_driver_impl[6cfe35843c87edd3]::run_compiler::{closure#0}>::{closure#0}
  42:     0x7fda6cb67949 - std[df2d6593d7194e63]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6c8aab51a4e81018]::util::run_in_thread_with_globals<rustc_interface[6c8aab51a4e81018]::util::run_in_thread_pool_with_globals<rustc_interface[6c8aab51a4e81018]::interface::run_compiler<core[50500588ec9d0052]::result::Result<(), rustc_span[9dcec85a30c01535]::ErrorGuaranteed>, rustc_driver_impl[6cfe35843c87edd3]::run_compiler::{closure#0}>::{closure#0}, core[50500588ec9d0052]::result::Result<(), rustc_span[9dcec85a30c01535]::ErrorGuaranteed>>::{closure#0}, core[50500588ec9d0052]::result::Result<(), rustc_span[9dcec85a30c01535]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[50500588ec9d0052]::result::Result<(), rustc_span[9dcec85a30c01535]::ErrorGuaranteed>>
  43:     0x7fda6cb67773 - <<std[df2d6593d7194e63]::thread::Builder>::spawn_unchecked_<rustc_interface[6c8aab51a4e81018]::util::run_in_thread_with_globals<rustc_interface[6c8aab51a4e81018]::util::run_in_thread_pool_with_globals<rustc_interface[6c8aab51a4e81018]::interface::run_compiler<core[50500588ec9d0052]::result::Result<(), rustc_span[9dcec85a30c01535]::ErrorGuaranteed>, rustc_driver_impl[6cfe35843c87edd3]::run_compiler::{closure#0}>::{closure#0}, core[50500588ec9d0052]::result::Result<(), rustc_span[9dcec85a30c01535]::ErrorGuaranteed>>::{closure#0}, core[50500588ec9d0052]::result::Result<(), rustc_span[9dcec85a30c01535]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[50500588ec9d0052]::result::Result<(), rustc_span[9dcec85a30c01535]::ErrorGuaranteed>>::{closure#1} as core[50500588ec9d0052]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  44:     0x7fda6dbe22d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6bfd5ba6e023a698
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/alloc/src/boxed.rs:2007:9
  45:     0x7fda6dbe22d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7da8003a07f4cffa
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/alloc/src/boxed.rs:2007:9
  46:     0x7fda6dbe22d5 - std::sys::unix::thread::Thread::new::thread_start::h64cf2021e889e721
                               at /rustc/4e3dc976e7876f59373ddc8ac176fe130636bcd1/library/std/src/sys/unix/thread.rs:108:17
  47:     0x7fda67aaa9eb - <unknown>
  48:     0x7fda67b2e7cc - <unknown>
  49:                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.76.0-nightly (4e3dc976e 2023-12-02) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(generic_const_exprs) -Z dump-mir-dir=dir

query stack during panic:
#0 [typeck] type-checking `_`
#1 [check_mod_item_types] checking item types in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0601`.

@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. F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Dec 2, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 2, 2023
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 2, 2023
@sjwang05
Copy link
Contributor

sjwang05 commented Dec 2, 2023

Reduced further:

#![feature(generic_const_exprs)]

struct Checked<const F: fn()>;

fn foo() {}
const _: Checked<foo> = Checked::<foo>;

searched nightlies: from nightly-2023-10-19 to nightly-2023-12-01
regressed nightly: nightly-2023-10-26
searched commit range: df871fb...ab5c841
regressed commit: ab5c841

bisected with cargo-bisect-rustc v0.6.7

Host triple: x86_64-pc-windows-msvc
Reproduce with:

cargo bisect-rustc

@matthiaskrgr
Copy link
Member Author

caused by #117159

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 19, 2024
@workingjubilee workingjubilee added the requires-incomplete-features This issue requires the use of incomplete features. label Jun 6, 2024
@bors bors closed this as completed in ea61714 Nov 12, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 12, 2024
Rollup merge of rust-lang#132927 - BoxyUwU:consolidate_type_system_const_eval, r=compiler-errors

Consolidate type system const evaluation under `traits::evaluate_const`

Part of rust-lang#130704

Fixes rust-lang#128232
Fixes rust-lang#118545

Removes `ty::Const::{normalize_internal, eval_valtree}` and `InferCtxt::(try_)const_eval_resolve`, consolidating the associated logic into `evaluate_const` in `rustc_trait_selection`. This results in an API for `ty::Const` that is free of any normalization/evaluation functions that would be incorrect to use under `min_generic_const_args`/`associated_const_equality`/`generic_const_exprs` or, more generally, that would be incorrect to use in the presence of generic type system constants.

Moving this logic to `rustc_trait_selection` and out of `rustc_middle` is also a pre-requisite for ensuring that we do not evaluate constants whose where clauses do not hold.

From this point it should be relatively simple (hah) to implement more complex normalization of type system constants such as: checking wf'ness before invoking CTFE machinery, or being able to normalize const aliases that still refer to generic parameters.

r? `@compiler-errors`
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-incomplete-features This issue requires the use of incomplete features. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
5 participants