Skip to content

ICE: primitive read not possible for type: fn(usize) -> bool {not_one} #137656

Open
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![feature(generic_const_exprs)]
#![feature(min_generic_const_args)]
struct Checked<const N: usize, const M: usize = { N + 1 }>;

fn not_one() -> bool {
    val != 1
}

fn main() {
    let _: Option<Checked<not_one>> = None;
}
original code

original:

//@ revisions: min adt_const_params full

#![cfg_attr(zero_init, feature(adt_const_params, unsized_const_params))]
#![cfg_attr(_bar, allow(incomplete_features))]
#![deny(type_alias_bounds)]
#![cfg_attr(adt_const_params, allow(incomplete_features))]

struct Checked<const N: usize, const M: usize = { N + 1 }>;
//~^ ERROR: using function pointers as const generic parameters

fn not_one(val: usize) -> bool {
    val != 1
}
fn not_two(val: usize) -> bool {
    val != 2
}

fn generic_arg<T>(val: T) -> bool {
    true
}

fn generic<const R: std::ops::RangeTo<usize>>(val: usize) -> bool {
    val != 1
}

fn main() {
    let _: Option<Checked<not_one>> = None;
    let _: Checked<not_one> = Checked::<not_one;
    let _: Checked<not_one> = Checked::<not_two>;

    let _ = Checked::<generic_arg>;
    let _ = Checked::<{ generic_arg::<usize> }>;
    let _ = Checked::<{ generic_arg::<u32> }>; //~ ERROR: mismatched types

    let _ = Checked::<generic>; //~ ERROR: type annotations needed
    let _ = Checked::<{ generic::<u16> }>;
    let _: Bar<{ Self::N }> = Checked::<{ generic::<u16> }>;
    let _: Checked<{ generic::<u32> }> = Checked::<{ None::<u16> }>;
}

Version information

rustc 1.87.0-nightly (cb06d1271 2025-02-25)
binary: rustc
commit-hash: cb06d12710575a0d7ff71d6fe108f3bcff4f9195
commit-date: 2025-02-25
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Possibly related line of code:

BackendRepr::Scalar(abi::Scalar::Initialized { .. })
| BackendRepr::ScalarPair(
abi::Scalar::Initialized { .. },
abi::Scalar::Initialized { .. }
)
) {
span_bug!(self.cur_span(), "primitive read not possible for type: {}", op.layout().ty);
}
let imm = self.read_immediate_raw(op)?.right().unwrap();
if matches!(*imm, Immediate::Uninit) {
throw_ub!(InvalidUninitBytes(None));
}
interp_ok(imm)

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

Program output

error[E0425]: cannot find value `val` in this scope
 --> /tmp/icemaker_global_tempdir.V3jy1D89mi7L/rustc_testrunner_tmpdir_reporting.gMvGGoVmhtCx/mvce.rs:4:5
  |
4 |     val != 1
  |     ^^^ not found in this scope

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

warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
 --> <crate attribute>:1:9
  |
1 | feature(min_generic_const_args)
  |         ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information

error: internal compiler error: compiler/rustc_const_eval/src/interpret/operand.rs:661:13: primitive read not possible for type: fn() -> bool {not_one}
 --> /tmp/icemaker_global_tempdir.V3jy1D89mi7L/rustc_testrunner_tmpdir_reporting.gMvGGoVmhtCx/mvce.rs:1:51
  |
1 | struct Checked<const N: usize, const M: usize = { N + 1 }>;
  |                                                   ^^^^^


thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/operand.rs:661:13:
Box<dyn Any>
stack backtrace:
   0:     0x7294b85b6a74 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h0d4d12f7c9404742
   1:     0x7294b8e1626c - core::fmt::write::h34bb49244168fa4a
   2:     0x7294b9e609d1 - std::io::Write::write_fmt::hd6e437e416d0bed7
   3:     0x7294b85b68d2 - std::sys::backtrace::BacktraceLock::print::hfca34c1e63219935
   4:     0x7294b85b90de - std::panicking::default_hook::{{closure}}::ha45a18105d446e7d
   5:     0x7294b85b8cb4 - std::panicking::default_hook::h6a80a3772ec5361c
   6:     0x7294b771e4d7 - std[b53140b4e800a389]::panicking::update_hook::<alloc[970020a2807e5699]::boxed::Box<rustc_driver_impl[1bbdac0c228310f]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7294b85b9953 - std::panicking::rust_panic_with_hook::h30dc2864a1afbdca
   8:     0x7294b775b171 - std[b53140b4e800a389]::panicking::begin_panic::<rustc_errors[ad2e37825b099599]::ExplicitBug>::{closure#0}
   9:     0x7294b774f586 - std[b53140b4e800a389]::sys::backtrace::__rust_end_short_backtrace::<std[b53140b4e800a389]::panicking::begin_panic<rustc_errors[ad2e37825b099599]::ExplicitBug>::{closure#0}, !>
  10:     0x7294b774f577 - std[b53140b4e800a389]::panicking::begin_panic::<rustc_errors[ad2e37825b099599]::ExplicitBug>
  11:     0x7294b7764b61 - <rustc_errors[ad2e37825b099599]::diagnostic::BugAbort as rustc_errors[ad2e37825b099599]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7294b7cabd7c - <rustc_errors[ad2e37825b099599]::DiagCtxtHandle>::span_bug::<rustc_span[e09ba479d632627]::span_encoding::Span, alloc[970020a2807e5699]::string::String>
  13:     0x7294b7d2dc6a - rustc_middle[d5845d7cf84c5da9]::util::bug::opt_span_bug_fmt::<rustc_span[e09ba479d632627]::span_encoding::Span>::{closure#0}
  14:     0x7294b7d171fa - rustc_middle[d5845d7cf84c5da9]::ty::context::tls::with_opt::<rustc_middle[d5845d7cf84c5da9]::util::bug::opt_span_bug_fmt<rustc_span[e09ba479d632627]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x7294b7d1706b - rustc_middle[d5845d7cf84c5da9]::ty::context::tls::with_context_opt::<rustc_middle[d5845d7cf84c5da9]::ty::context::tls::with_opt<rustc_middle[d5845d7cf84c5da9]::util::bug::opt_span_bug_fmt<rustc_span[e09ba479d632627]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x7294b65360c7 - rustc_middle[d5845d7cf84c5da9]::util::bug::span_bug_fmt::<rustc_span[e09ba479d632627]::span_encoding::Span>
  17:     0x7294b9ba9c77 - <rustc_const_eval[8e734e8eea3bdc64]::interpret::eval_context::InterpCx<rustc_const_eval[8e734e8eea3bdc64]::const_eval::machine::CompileTimeMachine>>::eval_rvalue_into_place
  18:     0x7294b9b4d64b - rustc_const_eval[8e734e8eea3bdc64]::const_eval::eval_queries::eval_to_allocation_raw_provider
  19:     0x7294b9b4c998 - rustc_query_impl[51c8df72720bccd9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[51c8df72720bccd9]::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d5845d7cf84c5da9]::query::erase::Erased<[u8; 24usize]>>
  20:     0x7294b9b463f6 - rustc_query_system[530b42b8e5b1fe1d]::query::plumbing::try_execute_query::<rustc_query_impl[51c8df72720bccd9]::DynamicConfig<rustc_query_system[530b42b8e5b1fe1d]::query::caches::DefaultCache<rustc_middle[d5845d7cf84c5da9]::ty::PseudoCanonicalInput<rustc_middle[d5845d7cf84c5da9]::mir::interpret::GlobalId>, rustc_middle[d5845d7cf84c5da9]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[51c8df72720bccd9]::plumbing::QueryCtxt, false>
  21:     0x7294b9b46075 - rustc_query_impl[51c8df72720bccd9]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace
  22:     0x7294b9b1f82b - rustc_const_eval[8e734e8eea3bdc64]::const_eval::valtrees::eval_to_valtree
  23:     0x7294b9b1f5fe - <rustc_const_eval[8e734e8eea3bdc64]::provide::{closure#0} as core[b342b8c3a7c37993]::ops::function::FnOnce<(rustc_middle[d5845d7cf84c5da9]::ty::context::TyCtxt, rustc_middle[d5845d7cf84c5da9]::ty::PseudoCanonicalInput<rustc_middle[d5845d7cf84c5da9]::mir::interpret::GlobalId>)>>::call_once
  24:     0x7294b9b1f59c - rustc_query_impl[51c8df72720bccd9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[51c8df72720bccd9]::query_impl::eval_to_valtree::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d5845d7cf84c5da9]::query::erase::Erased<[u8; 24usize]>>
  25:     0x7294b9b1f555 - <rustc_query_impl[51c8df72720bccd9]::query_impl::eval_to_valtree::dynamic_query::{closure#2} as core[b342b8c3a7c37993]::ops::function::FnOnce<(rustc_middle[d5845d7cf84c5da9]::ty::context::TyCtxt, rustc_middle[d5845d7cf84c5da9]::ty::PseudoCanonicalInput<rustc_middle[d5845d7cf84c5da9]::mir::interpret::GlobalId>)>>::call_once
  26:     0x7294b9b464cd - rustc_query_system[530b42b8e5b1fe1d]::query::plumbing::try_execute_query::<rustc_query_impl[51c8df72720bccd9]::DynamicConfig<rustc_query_system[530b42b8e5b1fe1d]::query::caches::DefaultCache<rustc_middle[d5845d7cf84c5da9]::ty::PseudoCanonicalInput<rustc_middle[d5845d7cf84c5da9]::mir::interpret::GlobalId>, rustc_middle[d5845d7cf84c5da9]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[51c8df72720bccd9]::plumbing::QueryCtxt, false>
  27:     0x7294b9b45f75 - rustc_query_impl[51c8df72720bccd9]::query_impl::eval_to_valtree::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7294b97152de - rustc_middle[d5845d7cf84c5da9]::query::plumbing::query_get_at::<rustc_query_system[530b42b8e5b1fe1d]::query::caches::DefaultCache<rustc_middle[d5845d7cf84c5da9]::ty::PseudoCanonicalInput<rustc_middle[d5845d7cf84c5da9]::mir::interpret::GlobalId>, rustc_middle[d5845d7cf84c5da9]::query::erase::Erased<[u8; 24usize]>>>
  29:     0x7294b97147c7 - <rustc_middle[d5845d7cf84c5da9]::ty::context::TyCtxt>::const_eval_global_id_for_typeck
  30:     0x7294b9714673 - <rustc_middle[d5845d7cf84c5da9]::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  31:     0x7294b97143e5 - rustc_trait_selection[480cac9937e0c320]::traits::try_evaluate_const
  32:     0x7294baa8aef0 - rustc_trait_selection[480cac9937e0c320]::traits::const_evaluatable::is_const_evaluatable.cold
  33:     0x7294b96b3292 - <rustc_trait_selection[480cac9937e0c320]::traits::fulfill::FulfillProcessor as rustc_data_structures[2e04112417d057ea]::obligation_forest::ObligationProcessor>::process_obligation
  34:     0x7294b8e0e229 - <rustc_data_structures[2e04112417d057ea]::obligation_forest::ObligationForest<rustc_trait_selection[480cac9937e0c320]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[480cac9937e0c320]::traits::fulfill::FulfillProcessor>
  35:     0x7294b9048f61 - <rustc_hir_typeck[23672bad03f101a5]::fn_ctxt::FnCtxt>::try_structurally_resolve_type
  36:     0x7294b9af188b - <rustc_hir_typeck[23672bad03f101a5]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  37:     0x7294b9af048b - <rustc_hir_typeck[23672bad03f101a5]::fn_ctxt::FnCtxt>::check_decl
  38:     0x7294b9aed4d9 - <rustc_hir_typeck[23672bad03f101a5]::fn_ctxt::FnCtxt>::check_expr_block
  39:     0x7294b9af409c - <rustc_hir_typeck[23672bad03f101a5]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  40:     0x7294b91c6ec9 - rustc_hir_typeck[23672bad03f101a5]::check::check_fn
  41:     0x7294b91ba06a - rustc_hir_typeck[23672bad03f101a5]::typeck_with_inspect::{closure#0}
  42:     0x7294b91b9670 - rustc_query_impl[51c8df72720bccd9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[51c8df72720bccd9]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d5845d7cf84c5da9]::query::erase::Erased<[u8; 8usize]>>
  43:     0x7294b91adc4c - rustc_query_system[530b42b8e5b1fe1d]::query::plumbing::try_execute_query::<rustc_query_impl[51c8df72720bccd9]::DynamicConfig<rustc_data_structures[2e04112417d057ea]::vec_cache::VecCache<rustc_span[e09ba479d632627]::def_id::LocalDefId, rustc_middle[d5845d7cf84c5da9]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[530b42b8e5b1fe1d]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[51c8df72720bccd9]::plumbing::QueryCtxt, false>
  44:     0x7294b91accdc - rustc_query_impl[51c8df72720bccd9]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7294b91ac97f - <rustc_middle[d5845d7cf84c5da9]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[211f361b4c3b663c]::check_crate::{closure#3}>::{closure#0}
  46:     0x7294b91abff9 - rustc_hir_analysis[211f361b4c3b663c]::check_crate
  47:     0x7294b91a651c - rustc_interface[e8bf2f6fd253e6de]::passes::run_required_analyses
  48:     0x7294b9e5c97a - rustc_interface[e8bf2f6fd253e6de]::passes::analysis
  49:     0x7294b9e5c959 - rustc_query_impl[51c8df72720bccd9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[51c8df72720bccd9]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d5845d7cf84c5da9]::query::erase::Erased<[u8; 0usize]>>
  50:     0x7294b9ecfb8b - rustc_query_system[530b42b8e5b1fe1d]::query::plumbing::try_execute_query::<rustc_query_impl[51c8df72720bccd9]::DynamicConfig<rustc_query_system[530b42b8e5b1fe1d]::query::caches::SingleCache<rustc_middle[d5845d7cf84c5da9]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[51c8df72720bccd9]::plumbing::QueryCtxt, false>
  51:     0x7294b9ecf879 - rustc_query_impl[51c8df72720bccd9]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  52:     0x7294b9f650fc - rustc_interface[e8bf2f6fd253e6de]::passes::create_and_enter_global_ctxt::<core[b342b8c3a7c37993]::option::Option<rustc_interface[e8bf2f6fd253e6de]::queries::Linker>, rustc_driver_impl[1bbdac0c228310f]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  53:     0x7294b9f58a20 - rustc_interface[e8bf2f6fd253e6de]::interface::run_compiler::<(), rustc_driver_impl[1bbdac0c228310f]::run_compiler::{closure#0}>::{closure#1}
  54:     0x7294b9d67d88 - std[b53140b4e800a389]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[e8bf2f6fd253e6de]::util::run_in_thread_with_globals<rustc_interface[e8bf2f6fd253e6de]::util::run_in_thread_pool_with_globals<rustc_interface[e8bf2f6fd253e6de]::interface::run_compiler<(), rustc_driver_impl[1bbdac0c228310f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  55:     0x7294b9d68534 - <<std[b53140b4e800a389]::thread::Builder>::spawn_unchecked_<rustc_interface[e8bf2f6fd253e6de]::util::run_in_thread_with_globals<rustc_interface[e8bf2f6fd253e6de]::util::run_in_thread_pool_with_globals<rustc_interface[e8bf2f6fd253e6de]::interface::run_compiler<(), rustc_driver_impl[1bbdac0c228310f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[b342b8c3a7c37993]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  56:     0x7294b9d69a2f - std::sys::pal::unix::thread::Thread::new::thread_start::h2c57420bbf26a3c6
  57:     0x7294b3ea370a - <unknown>
  58:     0x7294b3f27aac - <unknown>
  59:                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.87.0-nightly (cb06d1271 2025-02-25) running on x86_64-unknown-linux-gnu

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

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `Checked::{constant#0}`
#1 [eval_to_valtree] evaluating type-level constant
#2 [typeck] type-checking `main`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors; 2 warnings emitted

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

@rustbot label +F-generic_const_exprs +F-min_generic_const_args

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`F-min_generic_const_args`#![feature(min_generic_const_args)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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