rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.9k stars 12.68k forks source link

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

Open matthiaskrgr opened 2 months ago

matthiaskrgr commented 2 months ago

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 { | ^ 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 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 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 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::::call, 17); | ^^^^^^^^ thread 'rustc' panicked at compiler/rustc_infer/src/infer/mod.rs:1412:17: Box 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 - ::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::>::{closure#0} 11: 0x7f448e5081cf - as core::ops::function::Fn>::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::::{closure#0} 14: 0x7f448aa7d586 - std[7d30d51779b00fdc]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 15: 0x7f448aa78846 - std[7d30d51779b00fdc]::panicking::begin_panic:: 16: 0x7f448aa93c11 - ::emit_producing_guarantee 17: 0x7f448add7dcd - ::span_bug:: 18: 0x7f448adfdf98 - rustc_middle[79a84c3fef91123a]::util::bug::opt_span_bug_fmt::::{closure#0} 19: 0x7f448ae00eea - rustc_middle[79a84c3fef91123a]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 20: 0x7f448ade190b - rustc_middle[79a84c3fef91123a]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 21: 0x7f448a398237 - rustc_middle[79a84c3fef91123a]::util::bug::span_bug_fmt:: 22: 0x7f448ae17121 - ::try_const_eval_resolve 23: 0x7f44889b4cd5 - ::process_obligation 24: 0x7f448c273c0a - >::process_obligations:: 25: 0x7f448c55a5e6 - , ::consider_candidates::{closure#0}>, ::consider_candidates::{closure#1}> as core[ed9eac647662a901]::iter::traits::iterator::Iterator>::next 26: 0x7f448c565897 - ::pick_method 27: 0x7f448c564fa7 - ::pick_core 28: 0x7f448c508350 - ::probe_for_name 29: 0x7f448c51cbcf - ::check_expr_path 30: 0x7f448ca7e834 - ::check_expr_with_expectation_and_args 31: 0x7f448ca8180b - ::check_expr_with_expectation_and_args 32: 0x7f448ca85a2f - ::check_expr_with_expectation_and_args 33: 0x7f448ca73f69 - ::check_match::{closure#0} 34: 0x7f448ca8221e - ::check_expr_with_expectation_and_args 35: 0x7f448ca7aa5b - ::check_block_with_expected 36: 0x7f448ca8119d - ::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::> 40: 0x7f448c36d4b3 - rustc_query_system[b72a41914d7622ff]::query::plumbing::try_execute_query::>, 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 - ::par_body_owners::::{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::> 46: 0x7f448ce85265 - rustc_query_system[b72a41914d7622ff]::query::plumbing::try_execute_query::>, 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::, rustc_driver_impl[f229ff08257431b3]::run_compiler::{closure#0}>::{closure#1} 49: 0x7f448cd1a709 - std[7d30d51779b00fdc]::sys::backtrace::__rust_begin_short_backtrace::, 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 - <::spawn_unchecked_, 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 - as core::ops::function::FnOnce>::call_once::hdb8f7dfc3eda67f4 at /rustc/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/library/alloc/src/boxed.rs:2149:9 52: 0x7f448e51211b - as core::ops::function::FnOnce>::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 - 55: 0x7f448752a0dc - 56: 0x0 - 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

matthiaskrgr commented 2 months ago
#![feature(generic_const_exprs, unsized_const_params)]

fn function() {}

struct Wrapper<const F: fn()>;

impl Wrapper<{ bar() }> {
    fn call() {}
}

fn main() {
    Wrapper::<function>::call;
}
GrigorenkoPV commented 2 months ago

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);
}

Regression in #120847

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);
}

Regression in #121154

#![feature(generic_const_exprs, unsized_const_params)]

fn function() {}

struct Wrapper<const F: fn()>;

impl Wrapper<{ bar() }> {
    fn call() {}
}

fn main() {
    Wrapper::<function>::call;
}

Regression in #120847

BoxyUwU commented 2 months ago

Can be reproduced without unsized_const_params so removing that label