Skip to content

ICE: unable to construct a valtree for the unevaluated constant #128232

Closed
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![feature(generic_const_exprs, unsized_const_params, adt_const_params)]




fn function() -> u32 {
    17
}

struct Wrapper<const F: fn() -> u32>; 

impl<> Wrapper<bar(1, 1)> {
    
    fn call() -> u32 {
        F()
    }
}

fn main() {
    assert_eq!(Wrapper::<function>::call, 17);
}

original:

// Check that functions cannot be used as const parameters.
//@ revisions: min adt_const_params full

#![feature(generic_const_exprs, unsized_const_params, adt_const_params)]
#![zpk(full, allow(incomplete_features))]
#![cfg_attr(adt_const_params, feature(adt_const_params))]
#![cfg_attr(adt_const_params, allow(incomplete_features))]

fn function() -> u32 {
    17
}

struct Wrapper<const F: fn() -> u32>; //~ ERROR: using function pointers as const generic parameters

impl<const F: fn() -> u32> Wrapper<bar(1, 1)> {
    //~^ ERROR: using function pointers as const generic parameters
    fn call() -> u32 {
        F()
    }
}

fn main() {
    assert_eq!(Wrapper::<function>::call(generic_const_exprs, generic_arg_infer), 17);
}

Version information

rustc 1.82.0-nightly (6ef11b81c 2024-07-26)
binary: rustc
commit-hash: 6ef11b81c2c02c3c4b7556d1991a98572fe9af87
commit-date: 2024-07-26
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error: expected type, found `1`
  --> /tmp/icemaker_global_tempdir.ktOk6Uccai2q/rustc_testrunner_tmpdir_reporting.oullzuqu4Neh/mvce.rs:15:20
   |
15 | impl<> Wrapper<bar(1, 1)> {
   |                    ^ expected type
   |
help: expressions must be enclosed in braces to be used as const generic arguments
   |
15 | impl<> Wrapper<{ bar(1, 1) }> {
   |                +           +

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.ktOk6Uccai2q/rustc_testrunner_tmpdir_reporting.oullzuqu4Neh/mvce.rs:4:12
  |
4 | #![feature(generic_const_exprs, unsized_const_params, adt_const_params)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.ktOk6Uccai2q/rustc_testrunner_tmpdir_reporting.oullzuqu4Neh/mvce.rs:4:33
  |
4 | #![feature(generic_const_exprs, unsized_const_params, adt_const_params)]
  |                                 ^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information

error[E0741]: using function pointers as const generic parameters is forbidden
  --> /tmp/icemaker_global_tempdir.ktOk6Uccai2q/rustc_testrunner_tmpdir_reporting.oullzuqu4Neh/mvce.rs:13:25
   |
13 | struct Wrapper<const F: fn() -> u32>; 
   |                         ^^^^^^^^^^^

error[E0425]: cannot find function, tuple struct or tuple variant `F` in this scope
  --> /tmp/icemaker_global_tempdir.ktOk6Uccai2q/rustc_testrunner_tmpdir_reporting.oullzuqu4Neh/mvce.rs:18:9
   |
18 |         F()
   |         ^ not found in this scope

error: internal compiler error: compiler/rustc_infer/src/infer/mod.rs:1412:17: unable to construct a valtree for the unevaluated constant UnevaluatedConst { def: DefId(0:11 ~ mvce[ede4]::main::{constant#0}), args: [] }: type fn() -> u32 is not valtree-compatible
  --> /tmp/icemaker_global_tempdir.ktOk6Uccai2q/rustc_testrunner_tmpdir_reporting.oullzuqu4Neh/mvce.rs:23:26
   |
23 |     assert_eq!(Wrapper::<function>::call, 17);
   |                          ^^^^^^^^

thread 'rustc' panicked at compiler/rustc_infer/src/infer/mod.rs:1412:17:
Box<dyn Any>
stack backtrace:
   0:     0x7f448e505015 - std::backtrace_rs::backtrace::libunwind::trace::hba0c5d2da5d21d3b
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7f448e505015 - std::backtrace_rs::backtrace::trace_unsynchronized::h10df601c000a21db
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f448e505015 - std::sys::backtrace::_print_fmt::h9c09a69e66997be5
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/std/src/sys/backtrace.rs:68:9
   3:     0x7f448e505015 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h8df4565bb0e0abaf
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/std/src/sys/backtrace.rs:41:26
   4:     0x7f448e5549eb - core::fmt::rt::Argument::fmt::h2285a02bb70a7a85
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/core/src/fmt/rt.rs:173:76
   5:     0x7f448e5549eb - core::fmt::write::h9f3b68196c3b1892
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/core/src/fmt/mod.rs:1182:21
   6:     0x7f448e4f985f - std::io::Write::write_fmt::h6876ab44488ea710
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/std/src/io/mod.rs:1827:15
   7:     0x7f448e507801 - std::sys::backtrace::BacktraceLock::print::he09aebc2da930db5
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/std/src/sys/backtrace.rs:44:9
   8:     0x7f448e507801 - std::panicking::default_hook::{{closure}}::h84a3b946e31027b8
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/std/src/panicking.rs:269:22
   9:     0x7f448e5074dc - std::panicking::default_hook::hb8beb4cabfcfffe9
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/std/src/panicking.rs:296:9
  10:     0x7f448aa4f85a - std[7d30d51779b00fdc]::panicking::update_hook::<alloc[a425665f29645c95]::boxed::Box<rustc_driver_impl[f229ff08257431b3]::install_ice_hook::{closure#0}>>::{closure#0}
  11:     0x7f448e5081cf - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h2a1b73f9826d619d
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/alloc/src/boxed.rs:2163:9
  12:     0x7f448e5081cf - std::panicking::rust_panic_with_hook::hcb3a582e272725c3
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/std/src/panicking.rs:808:13
  13:     0x7f448aa8a5d1 - std[7d30d51779b00fdc]::panicking::begin_panic::<rustc_errors[858d6b59f6c606fd]::ExplicitBug>::{closure#0}
  14:     0x7f448aa7d586 - std[7d30d51779b00fdc]::sys::backtrace::__rust_end_short_backtrace::<std[7d30d51779b00fdc]::panicking::begin_panic<rustc_errors[858d6b59f6c606fd]::ExplicitBug>::{closure#0}, !>
  15:     0x7f448aa78846 - std[7d30d51779b00fdc]::panicking::begin_panic::<rustc_errors[858d6b59f6c606fd]::ExplicitBug>
  16:     0x7f448aa93c11 - <rustc_errors[858d6b59f6c606fd]::diagnostic::BugAbort as rustc_errors[858d6b59f6c606fd]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  17:     0x7f448add7dcd - <rustc_errors[858d6b59f6c606fd]::DiagCtxtHandle>::span_bug::<rustc_span[9dc2d37556667bfe]::span_encoding::Span, alloc[a425665f29645c95]::string::String>
  18:     0x7f448adfdf98 - rustc_middle[79a84c3fef91123a]::util::bug::opt_span_bug_fmt::<rustc_span[9dc2d37556667bfe]::span_encoding::Span>::{closure#0}
  19:     0x7f448ae00eea - rustc_middle[79a84c3fef91123a]::ty::context::tls::with_opt::<rustc_middle[79a84c3fef91123a]::util::bug::opt_span_bug_fmt<rustc_span[9dc2d37556667bfe]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7f448ade190b - rustc_middle[79a84c3fef91123a]::ty::context::tls::with_context_opt::<rustc_middle[79a84c3fef91123a]::ty::context::tls::with_opt<rustc_middle[79a84c3fef91123a]::util::bug::opt_span_bug_fmt<rustc_span[9dc2d37556667bfe]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7f448a398237 - rustc_middle[79a84c3fef91123a]::util::bug::span_bug_fmt::<rustc_span[9dc2d37556667bfe]::span_encoding::Span>
  22:     0x7f448ae17121 - <rustc_infer[5a8779d3ea9a51cc]::infer::InferCtxt>::try_const_eval_resolve
  23:     0x7f44889b4cd5 - <rustc_trait_selection[7be6dcd4e93fc1a0]::traits::fulfill::FulfillProcessor as rustc_data_structures[c4c8cdbb129cb916]::obligation_forest::ObligationProcessor>::process_obligation
  24:     0x7f448c273c0a - <rustc_data_structures[c4c8cdbb129cb916]::obligation_forest::ObligationForest<rustc_trait_selection[7be6dcd4e93fc1a0]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[7be6dcd4e93fc1a0]::traits::fulfill::FulfillProcessor>
  25:     0x7f448c55a5e6 - <core[ed9eac647662a901]::iter::adapters::filter::Filter<core[ed9eac647662a901]::iter::adapters::map::Map<core[ed9eac647662a901]::slice::iter::Iter<rustc_hir_typeck[ac02ac983fee86f6]::method::probe::Candidate>, <rustc_hir_typeck[ac02ac983fee86f6]::method::probe::ProbeContext>::consider_candidates::{closure#0}>, <rustc_hir_typeck[ac02ac983fee86f6]::method::probe::ProbeContext>::consider_candidates::{closure#1}> as core[ed9eac647662a901]::iter::traits::iterator::Iterator>::next
  26:     0x7f448c565897 - <rustc_hir_typeck[ac02ac983fee86f6]::method::probe::ProbeContext>::pick_method
  27:     0x7f448c564fa7 - <rustc_hir_typeck[ac02ac983fee86f6]::method::probe::ProbeContext>::pick_core
  28:     0x7f448c508350 - <rustc_hir_typeck[ac02ac983fee86f6]::fn_ctxt::FnCtxt>::probe_for_name
  29:     0x7f448c51cbcf - <rustc_hir_typeck[ac02ac983fee86f6]::fn_ctxt::FnCtxt>::check_expr_path
  30:     0x7f448ca7e834 - <rustc_hir_typeck[ac02ac983fee86f6]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  31:     0x7f448ca8180b - <rustc_hir_typeck[ac02ac983fee86f6]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  32:     0x7f448ca85a2f - <rustc_hir_typeck[ac02ac983fee86f6]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  33:     0x7f448ca73f69 - <rustc_hir_typeck[ac02ac983fee86f6]::fn_ctxt::FnCtxt>::check_match::{closure#0}
  34:     0x7f448ca8221e - <rustc_hir_typeck[ac02ac983fee86f6]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  35:     0x7f448ca7aa5b - <rustc_hir_typeck[ac02ac983fee86f6]::fn_ctxt::FnCtxt>::check_block_with_expected
  36:     0x7f448ca8119d - <rustc_hir_typeck[ac02ac983fee86f6]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  37:     0x7f448c1cc677 - rustc_hir_typeck[ac02ac983fee86f6]::check::check_fn
  38:     0x7f448c1c23c3 - rustc_hir_typeck[ac02ac983fee86f6]::typeck
  39:     0x7f448c1c1d69 - rustc_query_impl[6f72a32bb9596f00]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6f72a32bb9596f00]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[79a84c3fef91123a]::query::erase::Erased<[u8; 8usize]>>
  40:     0x7f448c36d4b3 - rustc_query_system[b72a41914d7622ff]::query::plumbing::try_execute_query::<rustc_query_impl[6f72a32bb9596f00]::DynamicConfig<rustc_query_system[b72a41914d7622ff]::query::caches::VecCache<rustc_span[9dc2d37556667bfe]::def_id::LocalDefId, rustc_middle[79a84c3fef91123a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6f72a32bb9596f00]::plumbing::QueryCtxt, false>
  41:     0x7f448c36c68d - rustc_query_impl[6f72a32bb9596f00]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  42:     0x7f448c36c28e - <rustc_middle[79a84c3fef91123a]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[799f0addd470a8f5]::check_crate::{closure#4}>::{closure#0}
  43:     0x7f448c36a0ce - rustc_hir_analysis[799f0addd470a8f5]::check_crate
  44:     0x7f448c360795 - rustc_interface[8d3212ab15a5ab63]::passes::analysis
  45:     0x7f448c360347 - rustc_query_impl[6f72a32bb9596f00]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6f72a32bb9596f00]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[79a84c3fef91123a]::query::erase::Erased<[u8; 1usize]>>
  46:     0x7f448ce85265 - rustc_query_system[b72a41914d7622ff]::query::plumbing::try_execute_query::<rustc_query_impl[6f72a32bb9596f00]::DynamicConfig<rustc_query_system[b72a41914d7622ff]::query::caches::SingleCache<rustc_middle[79a84c3fef91123a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[6f72a32bb9596f00]::plumbing::QueryCtxt, false>
  47:     0x7f448ce84fcf - rustc_query_impl[6f72a32bb9596f00]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  48:     0x7f448cd35385 - rustc_interface[8d3212ab15a5ab63]::interface::run_compiler::<core[ed9eac647662a901]::result::Result<(), rustc_span[9dc2d37556667bfe]::ErrorGuaranteed>, rustc_driver_impl[f229ff08257431b3]::run_compiler::{closure#0}>::{closure#1}
  49:     0x7f448cd1a709 - std[7d30d51779b00fdc]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[8d3212ab15a5ab63]::util::run_in_thread_with_globals<rustc_interface[8d3212ab15a5ab63]::util::run_in_thread_pool_with_globals<rustc_interface[8d3212ab15a5ab63]::interface::run_compiler<core[ed9eac647662a901]::result::Result<(), rustc_span[9dc2d37556667bfe]::ErrorGuaranteed>, rustc_driver_impl[f229ff08257431b3]::run_compiler::{closure#0}>::{closure#1}, core[ed9eac647662a901]::result::Result<(), rustc_span[9dc2d37556667bfe]::ErrorGuaranteed>>::{closure#0}, core[ed9eac647662a901]::result::Result<(), rustc_span[9dc2d37556667bfe]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ed9eac647662a901]::result::Result<(), rustc_span[9dc2d37556667bfe]::ErrorGuaranteed>>
  50:     0x7f448cd1a4ba - <<std[7d30d51779b00fdc]::thread::Builder>::spawn_unchecked_<rustc_interface[8d3212ab15a5ab63]::util::run_in_thread_with_globals<rustc_interface[8d3212ab15a5ab63]::util::run_in_thread_pool_with_globals<rustc_interface[8d3212ab15a5ab63]::interface::run_compiler<core[ed9eac647662a901]::result::Result<(), rustc_span[9dc2d37556667bfe]::ErrorGuaranteed>, rustc_driver_impl[f229ff08257431b3]::run_compiler::{closure#0}>::{closure#1}, core[ed9eac647662a901]::result::Result<(), rustc_span[9dc2d37556667bfe]::ErrorGuaranteed>>::{closure#0}, core[ed9eac647662a901]::result::Result<(), rustc_span[9dc2d37556667bfe]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ed9eac647662a901]::result::Result<(), rustc_span[9dc2d37556667bfe]::ErrorGuaranteed>>::{closure#1} as core[ed9eac647662a901]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  51:     0x7f448e51211b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hdb8f7dfc3eda67f4
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/alloc/src/boxed.rs:2149:9
  52:     0x7f448e51211b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h969b7c01506b8601
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/alloc/src/boxed.rs:2149:9
  53:     0x7f448e51211b - std::sys::pal::unix::thread::Thread::new::thread_start::he6f3cf1932d26a89
                               at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/std/src/sys/pal/unix/thread.rs:108:17
  54:     0x7f44874a6ded - <unknown>
  55:     0x7f448752a0dc - <unknown>
  56:                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: please make sure that you have updated to the latest nightly

note: rustc 1.82.0-nightly (6ef11b81c 2024-07-26) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors; 2 warnings emitted

Some errors have detailed explanations: E0425, E0741.
For more information about an error, try `rustc --explain E0425`.

@rustbot label +F-generic_const_exprs +F-unsized_const_params +F-adt_const_params

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-adt_const_params`#![feature(adt_const_params)]`F-generic_const_exprs`#![feature(generic_const_exprs)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions